Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by thechosenone570 · May 22, 2018 at 11:18 PM · unity 5unity5

I can't dynamically change the color of my particles

I'm having a problem changing the color of the particles dynamically. The code below allows me to select any number of colors and put them in a colors array. From there, I randomly select a color in Start() and save that value in myColor. Since it is saved to a global variable, I should be able to use it later right?

Well, this is where it gets tricky: I can assign that color to the material of the Something object. That seems to work fine. Then, I go to KillSomething(). If I Debug.Log myColor, it tells me its whatever color I'm expecting it to be. If I assign it to the particle startColor, though, I get nothing. If I hard code in a specific startColor (as shown below), the particles will show that color.

Why won't temp.startColor = myColor; work? But temp.startColor = Color.red; will?

 public class Something : MonoBehaviour {
 public Color[] colors;
 public Material somethingColor;
 public GameObject confetti;
 [HideInInspector]
 public Color myColor;

 void Start(){
     this.myColor = colors[Random.Range(0, colors.Length)];
     this.gameObject.transform.Find("Somethin/whatever").GetComponent<Renderer>().material.color = myColor;
 }

 public void KillSomething(){
 var c = Instantiate(confetti, transform.Find("Somethin/whatever").position, Quaternion.identity);
 var temp = c.transform.Find("Pieces").GetComponent<ParticleSystem>().main;
 temp.startColor = Color.red;
 Debug.Log(myColor.ToString());
 Destroy(c, 2f);
 Destroy(gameObject);
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by thechosenone570 · May 23, 2018 at 01:01 PM

I found the solution. For whatever reason, the alpha in myColor is 0. So, what I did was added a line of code just after I randomly choose the color:

 this.myColor = new Vector4(this.myColor.r, this.myColor.b, this.myColor.g, 1);

I don't know why it was assigning that color to the material in the line immediately after it, but whatever. I found a hackish way around it. Hope this helps others that have the same issue in the future

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Harinezumi · May 23, 2018 at 01:14 PM 0
Share

Are you sure that the colors in colors array had alpha different from 0? In the Editor Inspector the default alpha for a color variable is sometimes set to 0.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

174 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity 5 Android product name 1 Answer

UNET Player Object Creation Error: Failed to spawn server object 1 Answer

Fill Font Characters with White? 0 Answers

Start Application on second monitor 1 Answer

Why we have to use getcomponent instead of a simple reference ? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges