ParticleSystem.EmissionModule.rate is not a variable error
Working on updating my game after a hiatus, and the method I'm using to control a visual effect is now obsolete. Basically, I'm doing this on a particle system:
public override void UpdateEngines (float currentAccel) {
engineParticles.emission.rate = new ParticleSystem.MinMaxCurve(currentAccel * 200);
}
But it's complaining that ParticleSystem.EmissionModule is not a variable, so I can't assign a value to it. Yet the documentation here (http://docs.unity3d.com/ScriptReference/ParticleSystem-emission.html) shows that property being assigned a value.
What's the correct solution for this?
Okay, I found a working solution, but I don't understand /WHY/ I had to do this.
public override void UpdateEngines (float currentAccel) {
ParticleSystem.Emission$$anonymous$$odule em = engineParticles.emission;
em.rate = new ParticleSystem.$$anonymous$$in$$anonymous$$axCurve(currentAccel * 200);
}
Splitting the assignment into two lines fixes it. Why?!
It's all because Emission$$anonymous$$odule is a struct. In your case you modify a local copy of 'emission'. In a simple world you would probably want to assign a modified copy back to your particles. However, Unity implements emission's properties in a such way so it calls particle system internal methods. That's why it works.
Your answer
Follow this Question
Related Questions
Particle System trigger script not working,Particle system trigger script not working 0 Answers
Get ParticleSystem.SizeOverLifetime curve 0 Answers
Number of particles based on score collected? 1 Answer
Double animation curve 2 Answers
How do I change the shape scale in the Particle System via script? 1 Answer