Hi. I have some code that worked fine in Unity 3, and now constantly throws Exceptions in Unity 4. I suspect this is a bug.
If I even look at the value of target in my CustomEditor class, then a NRE happens, which shouldn’t happen. It appears to go through a broken accessor in Unity’s internal code.
The specific error is:
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Editor.get_referenceTargetIndex ()
UnityEditor.Editor.get_target ()
LDLevelObjectEditor.OnEnable () (at Assets/Editor/LDLevelObjectEditor.cs:63)
Line 63 in LDLevelObjectEditor is in OnEnable():
//line 63 is the one directly below
LDLevelObject o = target as LDLevelObject;
if ( o == null )
{
return;
}
You can see I even escape out if target does not exist for some reason. But the very nature of trying to access the target causes a NRE. I’m thinking it’s trying to get the target from a null GameObject, but that shouldn’t be possible if Unity is working correctly.
Also it’s worth noting that this happens during gameplay, which should never be the case since this is an Editor class.
Anybody encountered this and maybe know of a fix?