callen
1
I’m trying to tweak my particle systems in script, and I notice the needed “emissionRate” is deprecated in favor of an “emission” property.
ParticleSystem.emission is read-only, and is a struct, so trying to set PSystem.emission.rate = 5 does not work. The typical solution is to copy the struct, change it, and assign it back to the object (like you might do with transform.position or something).
But as this thread’s creator realizes, that doesn’t work because PSystem.emission is readonly. However, @richardkettlewell suggests not needing to reassign the struct, and that all you need is a temp var.
He says this code should work. And, in fact does:
ParticleSystem.EmissionModule em = particles.emission;
em.rate = new ParticleSystem.MinMaxCurve(5);
But everything I’ve learned in 10 years of C# coding says that this shouldn’t work. My new “em” variable should be a copy of emission, and modifying it should not be able to affect the source struct. In fact this is why the line “PSystem.emission.rate = 5” gives a compile error, because it knows this won’t work.
But somehow, it does work. Anyone know how? Afaik it seems impossible.
The particle modules are just interfaces to the particle system. They are not independent objects.
Internally they contain a reference to the particle system and calling get/set calls down into the c++ code.
We do this to avoid GC but still keep params in per module groups.