Warning on Setting Particle System Variable
I'm getting the following warning:
BCW0006: WARNING: Assignment to temporary.
On this code:
var gSteam: ParticleSystem;
gSteam.emission.rate.constant = 6;
Why would setting a particle system's emission variable be flagged as a temporary assignment?
Answer by Landern · Nov 15, 2016 at 08:31 PM
The constant property/field of rate is actually a struct of type MinMaxCurve named constant. Structs are copies and need to be set by passing a new struct, it is not a reference like classes offer you to keep it simplistic. Vector3 is also a struct but Unity while building the code out does the heavy lifting behind the curtains for you with unityscript/javascript, whereas with c# you have to fullly create a new Vector3 to set say the position of a GameObject. My suggestion is to pass the struct copy into a MinMaxCurve variable, change the constant field and apply it to the constant value.
var gSteam: ParticleSystem;
var tempMMC: MinMaxCurve = gSteam.emission.rate.constant;
tempMMC.constant = 6;
gStream.emission.rate.constant = tempMMC;
if you don't care about what the other values are you can just pass a new MinMaxCurve and the first parameter is the constant.
gSteam.emission.rate.constant = new MinMaxCurve(6);
@Landern Thanks, I get what you're saying. But those examples don't work. $$anonymous$$in$$anonymous$$axCurve is not a valid type. The second example says it's an unknown identifier. Changing it to new ParticleSystem.$$anonymous$$in$$anonymous$$axCurve(6) works, but that can't be assigned to the constant variable.
The only thing I could get to work was gS$$anonymous$$m.$$anonymous$$in$$anonymous$$axCurve(6); I didn't realize I could set it this way, also the other variables too if necessary.
Your answer
![](https://koobas.hobune.stream/wayback/20220612100738im_/https://answers.unity.com/themes/thub/images/avi.jpg)