ReorderableInspector icon indicating copy to clipboard operation
ReorderableInspector copied to clipboard

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

Open mages-gamedev opened this issue 6 years ago • 3 comments

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) };

mages-gamedev avatar Feb 21 '19 09:02 mages-gamedev

	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();
               ……
       }

MingFengShang avatar Jan 15 '20 07:01 MingFengShang

any fix for this?

delzrm avatar Jul 21 '20 20:07 delzrm

@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.

jerrod-storm avatar Jul 28 '20 03:07 jerrod-storm