Changing the size of a Particle System using a script. Cannot use UnityEngine in build

Im using a particle system for a ray of fire in my game. The length of my ray varies, so I had to figure out how to change the size of my particle system.

This approach works, but only in editor. When Im trying to build it complains that I cannot use UnityEditor.

    private UnityEditor.SerializedObject so1;

    public void UpdateRay()
    {

        so1.FindProperty("ShapeModule.boxZ").floatValue = dist;

        so1.ApplyModifiedProperties();

    }

Is there any other way to achieve this? This is the only way to do this I found and its completly useless (outside of editor)

You’ve discovered the wonderful world of “someone thought this level of API access was acceptable”! Fortunately there aren’t a lot of instances of this in the Unity engine, but the ParticleSystem class is… yeah, it’s pretty laughable. As far as I’m aware, you are pretty much SOL on that without getting a third-party particle system.

Fortunately, this issue is on the roadmap to be fixed in 5.3 (December) - might be worth trying to get ahold of the beta for that version.

1 Like

Yeah I was kind of worried that this was the case. Sadly Unity 5.3 is coming in december and thats a long wait :frowning:

The only other way to do this that I can think of would be to manually set the particle positions using some super complicated einstein level mathematical formula or just use a few different prefabs for different ray lengths.

This is just super frustrating