This has been a really long project, I started out in unity 3 and upgraded through 4 and now 5. This is one of the most strange things that I have encountered so far. Basically when upgrading from Unity 4 to 5, they made it so that we shouldn't call functions like NameToLayer anywhere( which was perfectly fine in Unity 4), they restrict it to be only called in functions like Awake(), Start()...etc.
Funny thing is, now I've removed every single call to LayerMask.NameToLayer in my entire project:
![alt text][1]
As you can see there are no references to the LayerMask.NameToLayer function at all in my project anymore. However, I'm still getting this every time I save a script and go back to the Unity Editor:
![alt text][2]
NameToLayer is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'GameSingleton' on game object 'GameSingleton'.
See "Script Serialization" page in the Unity Manual for further details.
UnityEngine.LayerMask:GetMask(String[])
GameSingleton:.cctor()
[1]: /storage/temp/94787-allref.png
[2]: /storage/temp/94788-exception.png
↧