Change startColor of ParticleSystem

Hi,

With the last version of Unity, if i change the startColor of a ParticleSystem using a script, a warning is displayed on the console saying startColor field is obsolete and main.startColor field must be used instead.
But when i use main.startColor, i have an error saying the field is read only.

Somebody has the same problem and found a solution ?

Thanks

Thomas

@tpanuel even though main is a struct, you can set it like this:

var main = myParticles.main;
main.startColor = Color.red;
2 Likes

Hey i had the same problem, i sort the code but for some reason its not assuming the color of the object i’m destroying.

Just to explain what i need, i’m working on a brickbreaker and when i’m destroying one i want to release some particles.
That part of the code is done, because the particles appear on the correct place.
The only thing not working is the particles assuming the color of the destroyed brick.
You can check the code below.

I’m calling the code from a function inside a function added to the brick object and the damage_effect is a prefab with the particle component.

    ...  
            levelManager.BrickDestroyed();
            Brick_particle();
            Destroy(gameObject);
    }

    public void Brick_particle()
    {
        GameObject dparticle = Instantiate(damage_effect, transform.position, Quaternion.identity) as GameObject;
        ParticleSystem.MainModule ps = dparticle.GetComponent<ParticleSystem>().main;
        ps.startColor = GetComponent<SpriteRenderer>().color;

        Debug.Log("Brick Color: " + GetComponent<SpriteRenderer>().color + " | effect: " + ps.startColor);
    }

The debug code gives me this
Brick Color: RGBA(0.834, 0.896, 0.106, 1.000) | effect: UnityEngine.ParticleSystem+MinMaxGradient
Another test i made:
I try to add the prefab on the stage and change the color manually and it’s not changing. I also have unmark the “Color over Lifetime” and “Color by speed” properties.

Apreciate your help,