Now what confuses me is that I cannot use both at the same time. I mean, if a MonoBehavior script has a method with an optional parameter, no problem. If a MonoBehavior script is in a namespace, no problem as well. But if a MonBehavior script is in a namespace AND has a method with an optional parameter, it breaks (the console message falsely claims the name of the class wouldn’t match the file).
Not true, any method that uses default arguments in the method signature, even those not overridden/etc from MonoBehaviour will still cause issues and produce either error, depending on how the script is attached:
If the script is already attached and you change the method signature, or add through add components
“The associated script can not be loaded. Please fix any compile errors and assign a valid script”
If the script is dragged onto the object to add
Name script mismatch
This should either be a documented problem to avoid or a fix, because I spent two hours on this.
I tell you what…you should not REALLY use optional parameters in c#. They have been introduced only to be compatible with CLI languages and they do not belong to the c# syntax.
I find this bug quite terrible. Bumping the thread.
@sebas77: (hey Seba ;)) whatever the reason for introducing optional parameters, they are indeed very useful, especially to keep the code tidy when you don’t really need overloads. Is there some real reason why we should not use them (Unity bugs apart)?
This bug was fixed for classes only. But they did not fixe it for structs containing methods with default arguments or static functions as well. This gives me a lot of headache the first time i encountered it. Unity pls fix this bug with all its corner cases.
God I just spent two hours slowly by slowly pulling out various bits of code trying to figure out what was actually triggering this problem. To the point where I had it narrowed down to the presence of one function. Then I removed each argument one by one, damn frustrating.
“same same but different, yet still the same” - I add an optional parameter (with default value) to a public function and want to attach the function to an EventTrigger (mouseover for example) - not possible. The function doesn’t even appear on the list, acts like if it was a private member…