I have the following code to modify a property of the ParticleSystem in Unity
waterCone.main.loop = true;
However, this is giving me the following error
Property 'main' access returns temporary value. Cannot modify struct member when accessed struct is not classified as a variable
Unity's own docs seem to show this code being used as follows
var waterConeMain = waterCone.main;
waterConeMain.loop = true;
With no errors at all.
Why does this fix the problem, as far as my understanding of c# goes, this should be the exact same.
In fact, as far as I can tell neither should work.
I tried to compare the two in Sharplab but the first would not even compile.
What's going on here? And why is this variable necessary?
(edit)
From looking into the source code, it looks like ParticleSystem.main is doing this
MainModule main => new MainModule(this);
And Main is a struct, which has loop as a property like
get => ParticleSystem.MainModule.get_loop_Injected(ref this);
set => ParticleSystem.MainModule.set_loop_Injected(ref this, value);
But really this seems to leave me with more questions than answers, why is this a compilation error when I don't use a temporary variable?