New Unity version(5.3.0) change the particleSystem:
All UI settings exposed to scripting API, but all setting property is readonly.
Hao to modify setting property in script?
Not sure why but instead of calling:
m_particleSystem.enableEmission = true;
or
m_particleSystem.emission.enabled = true
In Unity 5.3 you have to call:
ParticleSystem.EmissionModule em = m_particleSystem.emission;
em.enabled = true;
Rather than particleSystem.emission.enabled = true
Do:
var em = particleSystem.emission;
em.enabled = true;
That worked for me.
@carsonig
Disassembling explains why ParticleSystem.EmissionModule is struct but it works for struct
var em = particleSystem.emission;
em.enabled = true;
Yes, em.enabled which creates the new instance of EmissionModule but with copy of reference to particleSystem itself.
So as the result em.enabled = true; is the call to static C++ void SetEnabled(ParticleSystem particleSystem , bool value);
this struct is used to pass the reference to object to native part of engine, nothing more.
So nothing strange that it works but from C# paradigm it looks unexpected, you are right here
At long last! After looking through the forums and finding this article: http://forum.unity3d.com/threads/enabling-emission.364258/#post-2356966, it turns out that the best way to do this is as follows.
ParticleSystem.EmissionModule em = GetComponent <ParticleSystem> ().emission; em.enabled = true;
And it works! Sorry about the crappy formatting, this is one of my first times answering a question on these forums.
I found modify the struct members will work, but the code is seem bad.
var emmision = particle.emmision;
emmision.enable = false;
That’s so weird, because emission is a struct… so var em = particleSystem.emission makes a copy, meaning it shouldn’t affect the emission struct that is attached to the particle system