Particle system script colour

Hey,

I have a “ParticleSystem” with a “Start Color” set to be random between two colours.

Via script using:

ParticleSystem.startColor = Color.red; 

The start colour of slot one will be set to red, the second slot will remain whatever it was set to in the editor but you are certainly able to access the ParticleSystem as I have successfully altered the first half of the random start colour.

My question, is there any way to set the second of the two randomised colours via script? There is nothing on the scripting page that indicates how one might access the second colour.

I was assuming something like this might be available:

ParticleSystem.startColor[1] = Color.red; 

But obviously I know this refers to the second component of the particle systems colour.

Thanks in advance for any help.

For anyone else who may find this useful, it looks like this cannot be done at run time. You’d need to access the particle systems → InitialModule → colorMin/colorMax, which can be found if you set your inspector to debug mode, and this does not seem possible as mentioned in the comments in the below answer page.

Leaving an example for future references:

        ParticleSystem.MainModule main = GetComponent().main;
        var startColor = main.startColor;

        startColor.colorMax = anyColor1;
        startColor.colorMin = anyColor2;

        main.startColor = startColor;

This CAN be done, and it has been answered here: https://forum.unity.com/threads/setting-particle-system-startcolors-value-with-gradient-or-2-values-through-c.437926/