Cannot Change emission.rate
I have been using emissionRate as a variable without problem, but I recently got a notification in unity that it is obsolete and I should use emission.rate. When I try that, it tells me that it is read only and I should consider storing the value in a temporary variable. I have done this before with the alpha value of colors, but I don't know how to do this with the rate. Does anyone know how to modify emission.rate?
Thanks.
Answer by mikelortega · Jul 19, 2016 at 10:35 AM
You can change the rate this way:
var rate = myParticleSystem.emission.rate;
rate.mode = ParticleSystemCurveMode.Constant;
rate.constantMin = xxx;
rate.constantMax = xxx;
Answer by NetherChef · May 26, 2018 at 07:14 AM
What you want to change is ParticleSystem.emission.rateOverTime.constant. To change this, you need:
ParticleSystem yourParticleSys;
ParticleSystem.EmissionModule yourEmissionModule;
float newEmissionrate = 100;
Make EmissionModule inherit from ParticleSystem:
yourEmissionModule = particleSys.emission;
ParticleSystem.emission.rateOverTime is not a float/int but a ParticleSystem.MinMaxCurve. So, to change it do:
ParticleSystem.MinMaxCurve tempCurve = yourEmissionModule.rateOvertTime;
tempCurve.constant = newEmissionRate;
yourEmissionModule.rateOverTime = tempCurve;
Answer by richardzzzarnold · Nov 08, 2019 at 09:01 AM
If you want to have an animated emission rate would you have this whole bit in an Update function?
ParticleSystem.MinMaxCurve tempCurve = yourEmissionModule.rateOvertTime;
tempCurve.constant = newEmissionRate;
yourEmissionModule.rateOverTime = tempCurve;