- Home /
Null Reference using IMGUIContainer and array fields
In my project I have a custom editor for a subclass of (a subclass of) a ScriptableObject that is using UIElements. In order to show its base classes editor, I am using an IMGUIContainer.
public override VisualElement CreateInspectorGUI()
{
this.tree = GrowableEditor.BuildContainer("TrackInspector");
var baseInspector = new IMGUIContainer(this.OnInspectorGUI);
this.tree.Add(baseInspector);
return this.tree;
}
This is working, but when I highlight the value in any serialized array's size field I get the following Null ref
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.EditorGUI+RecycledTextEditor.IsEditingControl (System.Int32 id) (at <887a438259064e89922419bc7b8810ab>:0)
UnityEditor.EditorGUI.DelayedTextFieldInternal (UnityEngine.Rect position, System.Int32 id, UnityEngine.GUIContent label, System.String value, System.String allowedLetters, UnityEngine.GUIStyle style) (at <887a438259064e89922419bc7b8810ab>:0)
UnityEditor.EditorGUI.ArraySizeField (UnityEngine.Rect position, UnityEngine.GUIContent label, System.Int32 value, UnityEngine.GUIStyle style) (at <887a438259064e89922419bc7b8810ab>:0)
UnityEditor.EditorGUI.DefaultPropertyField (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at <887a438259064e89922419bc7b8810ab>:0)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at <887a438259064e89922419bc7b8810ab>:0)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at <887a438259064e89922419bc7b8810ab>:0)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at <887a438259064e89922419bc7b8810ab>:0)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at <887a438259064e89922419bc7b8810ab>:0)
UnityEditor.PropertyHandler.OnGUILayout (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at <887a438259064e89922419bc7b8810ab>:0)
UnityEditor.EditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at <887a438259064e89922419bc7b8810ab>:0)
UnityEditor.EditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, System.Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at <887a438259064e89922419bc7b8810ab>:0)
UnityEditor.Editor.DoDrawDefaultInspector (UnityEditor.SerializedObject obj) (at <887a438259064e89922419bc7b8810ab>:0)
UnityEditor.Editor.DoDrawDefaultInspector () (at <887a438259064e89922419bc7b8810ab>:0)
UnityEditor.Editor.DrawDefaultInspector () (at <887a438259064e89922419bc7b8810ab>:0)
UnityEditor.Editor.OnInspectorGUI () (at <887a438259064e89922419bc7b8810ab>:0)
UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Boolean canAffectFocus) (at <085559680b9141e8b8c144c684aaa6d7>:0)
UnityEditor.UIElements.Tooltip:SetTooltip(Single, Single)
It does not seem to cause any major issue, other than the error spam and resetting the scroll position, but was wondering if there is a way to avoid this?
Your answer
Follow this Question
Related Questions
Custom inspector, a multidimensional array of enums 1 Answer
Can't drag slider onto inspector 1 Answer
Array of custom properties? (C#) 1 Answer
Why ExecuteInEditMode Always Causes NullReferenceException Errors Even In Clamping!! 2 Answers
(Logic) Switch GameObjects With Slider Using Arrays 0 Answers