Anyone know how to identify what is raising this error. I’ve just noticed it after a fair amount of fiddling and have presumably started calling something from edit mode - but I can’t work out what :S
In my case this appears to caused by “HideAndDontSave” objects - but I presume it must actually be something I’m doing with them…
I have experienced this problem before. Here is how I resolved it:
public class MyEditorWindow : EditorWindow {
[System.NonSerialized]
public BehaviourTree tree;
}
Here is what I discovered.
At edit time the variable tree
in the editor window points towards towards a valid object. Let’s call this object instance A.
When play mode is entered the objects get reloaded and thus re-instantiated. As such the tree object is now instance B. Though, for some reason the variable in the editor window still points to instance A. And to make matters worse the editor window variable is non-null and incorrectly A == B.
Upon returning to edit mode the editor window still references instance A, however by now we are using instance C. And again, the variable in the editor window is non-null and incorrectly tests true for A == C.
Thus, preventing the variable from being serialized will cause the variable to become null
upon switching between play mode and edit mode. You can then reload the variable when it is null
and this should solve the problem.
Edit: Btw, you may need to reload your project for this change to take effect. I cannot remember if I had to or not…
So in my case this was caused by having any objects set to HideAndDontSave which I guess implies it might be a bug as this used to work just fine.
If I had a HideAndDontSave object I would get !IsPlayingOrAllowInExecuteMode any time the dirty flag was set on any object in the editor.
In my case I tried solve it replacing OnApplicationQuit() by OnDestroy() and it worked only once. I do a clean up for several private static lists. Then I figure out that having next line in methods OnDestroy() and/or OnApplicationQuit() was the root of the problem (again, only in my case)
instance = null;
Once I removed that line, no more !IsPlayingOrAllowExecuteInEditMode.