How did this go?
The docs don’t explicitly say ‘use var’. I just saw that the code samples used var.
Emission Module ‘enable’ documentation
The code sample shows
void Update()
{
var emission = ps.emission; // 'var' here. other docs do the same
emission.enabled = moduleEnabled;
}
I remembered that the EmissionModule
is a struct and when you get a reference to it, you actually get a copy that needs to be given back. Usually
var emission = particles.emission;
emission.enabled = true;
particles.emission = emission;
but even Unity’s documentation didn’t do this, so I was intrigued. Did some more digging. That’s when I saw they said that the module is an interface and does not need to be passed back
Emission Module documentation
So, I just figured the var is what makes their code work over yours because it’s pretty much the only difference between the two. Not entirely sure, but I think when you define it explicitly the compiler calls the constructor of the type in order to cast the interface to the type and this is what triggers the error you got