Exposed ParticleSystem API is very limitted (Unity - Scripting API: ParticleSystem). For example you can not access “Size over lifetime” or “Rotation over lifetime” or simply set lifetime as “random between two constants” from script.
Has anyone found a way to do that? Through reflection? Through some hack using the inspector script?
It looks like it’s possible, it’s just not very straight forward. You can modify private variables using this trick:
var so : SerializedObject = new SerializedObject(Selection.activeGameObject.GetComponent(Renderer));
so.FindProperty("m_ScaleInLightmap").floatValue = 0.9;
You can iterate all serializable properties using this loop:
SerializedObject so = new SerializedObject(particleSystem);
SerializedProperty it = so.GetIterator();
After that you will notice that ParticleSystem has a bunch of properties like InitialModule, SizeModule, etc. Each sub-property like InitialModule.startLifetime has a property minMaxState (int value from 0 to 3) representing 4 states:
- Random between two constants
- Random between two curves
There are three properties to store these values: scalar, minCurve, maxCurve. Note that minCurve/maxCurve.keys.value is used for storing extra data for “Random between two constants”.