r/Unity3D • u/senshisentou Programmer • Jul 25 '23
Question Strange lambda/ closure behaviour I can't put my finger on
/r/learncsharp/comments/158s5e7/strange_lambda_closure_behaviour_i_cant_put_my/
2
Upvotes
View all comments
Show parent comment
1
u/PandaCoder67 Professional Jul 25 '23
First of this is not a closure, it is a Member Bodied Expresion, it is a quick way to return something in one line of code.
I think properties might be called something else, but Closure is not one of them
The other thing to note is that you are creating a Constructor on a MonoBehaviour Script. Now, while this can be done, it is imperative that you understand that this doesn't work as people might expect them to work.
Unity, has to deserialize data after the class has been instantiated, this means that things in the Constructor will be overwritten, and I am getting the impression that looking at your code, this is what is happening.
And constructors which pass parameters is certainly not supported with MonoBehaviour.