Null Reference for List<ScriptableObject> members when adding a new element

Issue #972 resolved
János Szabó created an issue

The problem

Odin throws a null reference error for List<ScriptableObject> type of members when adding a new element. Also, the new element is not added, thus it breaks standard Unity functionality.

Steps to reproduce

  1. Create a MonoBehaviour with the following public member:

    public class MyMonoBehaviour { public List<ScriptableObject> mySOList = new(); }

  2. Put the script on a GameObject in the Unity Editor.

  3. Press the “Add” button on the inspector panel.
  4. The object picker panel opens, but the console just shows a new error message:

    5. After selecting an ScriptableObject asset in the object picker panel, it does not add it to the list.

Unfortunately, this breaks the whole workflow process for me with Odin Inspector, thus until I get a hint about how to avoid this issue until an official fix, I consider it a critical issue.

Environment

Unity: 2023.2.10f1

Odin: 3.2.1.0

OS: Windows 11 Pro, latest updates, all drivers official/stable.

Console message

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Search.SearchView.SetSearchText (System.String searchText, UnityEditor.Search.TextCursorPlacement moveCursor) (at <8d93267f50664238a2d0910f0b05f4b3>:0)
UnityEditor.Search.SearchWindow.SetSearchText (System.String searchText, UnityEditor.Search.TextCursorPlacement moveCursor, System.Int32 cursorInsertPosition) (at <8d93267f50664238a2d0910f0b05f4b3>:0)
UnityEditor.Search.SearchWindow.SetSearchText (System.String searchText, UnityEditor.Search.TextCursorPlacement moveCursor) (at <8d93267f50664238a2d0910f0b05f4b3>:0)
UnityEditor.Search.DefaultAdvancedObjectSelector.SetSearchFilter (UnityEditor.SearchService.AdvancedObjectSelectorParameters& parameters) (at <8d93267f50664238a2d0910f0b05f4b3>:0)
UnityEditor.Search.DefaultAdvancedObjectSelector.HandleAdvancedObjectSelectorEvents (UnityEditor.SearchService.AdvancedObjectSelectorEventType eventType, UnityEditor.SearchService.AdvancedObjectSelectorParameters& parameters) (at <8d93267f50664238a2d0910f0b05f4b3>:0)
UnityEditor.Search.ObjectSelectorEngine.SetSearchFilter (UnityEditor.SearchService.ISearchContext context, System.String searchFilter) (at <8d93267f50664238a2d0910f0b05f4b3>:0)
UnityEditor.SearchService.ObjectSelectorSearch.SetSearchFilter (System.String searchFilter, UnityEditor.SearchService.ObjectSelectorSearchContext context) (at <f996ea1d0cd640ed95a84d75e3b1431c>:0)
UnityEditor.SearchService.ObjectSelectorSearchSessionHandler.SetSearchFilter (System.String searchFilter) (at <f996ea1d0cd640ed95a84d75e3b1431c>:0)
UnityEditor.ObjectSelector.set_searchFilter (System.String value) (at <f996ea1d0cd640ed95a84d75e3b1431c>:0)
UnityEditor.EditorGUIUtility.SetupObjectSelector (UnityEngine.Object obj, System.Type objType, System.Boolean allowSceneObjects, System.String searchFilter, System.Int32 controlID) (at <f996ea1d0cd640ed95a84d75e3b1431c>:0)
UnityEditor.EditorGUIUtility.ShowObjectPicker[T] (UnityEngine.Object obj, System.Boolean allowSceneObjects, System.String searchFilter, System.Int32 controlID) (at <f996ea1d0cd640ed95a84d75e3b1431c>:0)
System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <20deccf348554c238921b06fec015ff8>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <20deccf348554c238921b06fec015ff8>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <20deccf348554c238921b06fec015ff8>:0)
Sirenix.Utilities.Editor.ObjectPicker.ShowObjectPicker (System.Object currValue, System.Boolean allowSceneObjects, UnityEngine.Rect buttonRect, System.Boolean disallowNullValues) (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.Utilities.Editor/InstanceResolver/ObjectPicker.cs:206)
Sirenix.OdinInspector.Editor.Drawers.CollectionDrawer`1[T].StartCreatingValues (UnityEngine.Rect potentialPopupPosition) (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Value Drawers/CollectionDrawer.cs:1156)
Sirenix.OdinInspector.Editor.Drawers.CollectionDrawer`1[T].DrawToolbar () (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Value Drawers/CollectionDrawer.cs:1109)
Sirenix.OdinInspector.Editor.Drawers.CollectionDrawer`1[T].DrawPropertyLayout (UnityEngine.GUIContent label) (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Value Drawers/CollectionDrawer.cs:656)
Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (UnityEngine.GUIContent label) (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155)
Sirenix.OdinInspector.Editor.Drawers.NullableReferenceDrawer`1[T].DrawPropertyLayout (UnityEngine.GUIContent label) (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/NullableReferenceDrawer.cs:113)
Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (UnityEngine.GUIContent label) (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155)
Sirenix.OdinInspector.Editor.Drawers.FixUnityNullDrawer`1[T].DrawPropertyLayout (UnityEngine.GUIContent label) (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/FixUnityNullDrawer.cs:87)
Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (UnityEngine.GUIContent label) (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155)
Sirenix.OdinInspector.Editor.Drawers.ReferenceDrawer`1[T].DrawPropertyLayout (UnityEngine.GUIContent label) (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/ReferenceDrawer.cs:118)
Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (UnityEngine.GUIContent label) (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155)
Sirenix.OdinInspector.Editor.Drawers.PropertyContextMenuDrawer`1[T].DrawPropertyLayout (UnityEngine.GUIContent label) (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/PropertyContextMenuDrawer.cs:659)
Sirenix.OdinInspector.Editor.OdinDrawer.DrawProperty (UnityEngine.GUIContent label) (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:109)
Sirenix.OdinInspector.Editor.InspectorProperty.Draw (UnityEngine.GUIContent defaultLabel) (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:849)
Rethrow as OdinPropertyException: This error occurred while being drawn by Odin.
Current IMGUI event: Used
Odin Property Path: _mySOList
Odin Drawer Chain:
> PropertyContextMenuDrawer<List<ScriptableObject>>
> ReferenceDrawer<List<ScriptableObject>>
> FixUnityNullDrawer<List<ScriptableObject>>
> NullableReferenceDrawer<List<ScriptableObject>>
> CollectionDrawer<List<ScriptableObject>>
> CompositeDrawer.
UnityEngine.Debug:LogException(Exception)
Sirenix.OdinInspector.Editor.InspectorProperty:Draw(GUIContent) (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:926)
Sirenix.OdinInspector.Editor.InspectorProperty:Draw() (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:737)
Sirenix.OdinInspector.Editor.Drawers.UnityObjectRootDrawer`1:DrawPropertyLayout(GUIContent) (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Value Drawers/UnityObjectRootDrawer.cs:60)
Sirenix.OdinInspector.Editor.OdinDrawer:CallNextDrawer(GUIContent) (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155)
Sirenix.OdinInspector.Editor.Drawers.FixBrokenUnityObjectWrapperDrawer`1:DrawPropertyLayout(GUIContent) (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Attribute Drawers/FixBrokenUnityObjectWrapperDrawer.cs:41)
Sirenix.OdinInspector.Editor.OdinDrawer:DrawProperty(GUIContent) (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:109)
Sirenix.OdinInspector.Editor.InspectorProperty:Draw(GUIContent) (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:849)
Sirenix.OdinInspector.Editor.PropertyTree:DrawProperties() (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/PropertyTree.cs:552)
Sirenix.OdinInspector.Editor.PropertyTree:Draw(Boolean) (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/PropertyTree.cs:444)
Sirenix.OdinInspector.Editor.OdinEditor:DrawTree() (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinEditor.cs:98)
Sirenix.OdinInspector.Editor.OdinEditor:DrawOdinInspector() (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinEditor.cs:232)
Sirenix.OdinInspector.Editor.OdinEditor:OnInspectorGUI() (at Y:/Repos/Sirenix-Development-Framework/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinEditor.cs:80)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

Comments (8)

  1. János Szabó reporter

    If I turn off the “Enable Odin In Inspector” in the Odin preferences the issue goes away.

  2. Lucas Schwaner

    Hey, thanks for the heads up, this issue should be fixed in 3.3 with the introduction of the new Object Picker.

  3. János Szabó reporter

    Hey, great news! When will it be merged into the main release to download through Package Manager?

  4. János Szabó reporter

    @Lucas Schwaner Is there an update on where it will be available? Or can you give me a hint how can I use Odin until it is published in the stable branch? Thx.

  5. Log in to comment