While developing a game as intermediate and final project for studying in Unity I find several gotchas and want to share them with you. This time:
#if UNITY_EDITOR
Everything works smooth in editor, because every script has the exact same layout .. but don't try to build and run it because that will fail in every possible way.
You used EditorUtility.SetDirty(this);
?
Well .. Unity will complain that it cannot compile scripts because the reference UnityEditor.dll
could not been found.
What does every developer do now? Right, #if UNITY_EDITOR
.
Building works perfectly now but it neither display anything nor crash because Unity is of the opinion that everything is okay although it spams output-log.txt
with something like
The referenced script on this Behaviour is missing!
(Filename: Line: 1715)
A script behaviour has a different serialization layout when loading. (Read 44 bytes but expected 76 bytes) Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?
That's rather bad because you had things to do in this serialized object which should do different things in editor (setting itself as dirty) but that method is now gone aswell. Only option left is to let the inspector set the object dirty but .. that's dirty :D