SubjectNerd-Unity / ReorderableInspector

Automatic reorderable lists for Unity game engine components
MIT License
485 stars 47 forks source link

NullReferenceException: Object reference not set to an instance of an object UnityEditor.EditorStyles.get_helpBox () #14

Open mages-gamedev opened 5 years ago

mages-gamedev commented 5 years ago

Upon recompilation of scripts, an error consistently pops up

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.EditorStyles.get_helpBox () (at C:/buildslave/unity/build/Editor/Mono/GUI/EditorStyles.cs:195)
SubjectNerd.Utilities.ReorderableArrayInspector.InitInspector () (at Assets/ThirdParty/SubjectNerd/ReorderableInspector/Editor/ReorderableArrayInspector.cs:326)
SubjectNerd.Utilities.ReorderableArrayInspector.OnEnable () (at Assets/ThirdParty/SubjectNerd/ReorderableInspector/Editor/ReorderableArrayInspector.cs:311)

This is the line throwing the null ref error:

styleEditBox = new GUIStyle(EditorStyles.helpBox) { padding = new RectOffset(5, 5, 5, 5) };
MingFengShang commented 4 years ago
    private void OnEnable()
    {
        //InitInspector();
    }
        ……
        protected bool InspectorGUIStart(bool force = false)
    {
        InitInspector();
        Repaint(); 
        // Not initialized, try initializing
        //if (hasSortableArrays && listIndex.Count == 0)
        //  InitInspector();
        //if (hasEditable && editableIndex.Count == 0)
        //  InitInspector();
               ……
       }
delzrm commented 4 years ago

any fix for this?

jaredstorm commented 4 years ago

@delzrm -- This isn't a real fix, but you can at least suppress the errors by wrapping the offending line with a try/catch.

      try {
        styleEditBox = new GUIStyle(EditorStyles.helpBox) { padding = new RectOffset(5, 5, 5, 5) };
      } catch (Exception) {

      }

You're not really supposed to use try/catch like this since it's terrible for performance, but seeing as it's in an initialization method in an Editor script, it's not really a performance critical segment of code.