ValueDropdown not saving or passing a null value to == override

Issue #869 new
David W created an issue

What happened?

I am trying to create a dropdown for a custom object for each layer in my world. If I don’t use ValueDropdown then the array will show, but it will not list the custom objects. If I use ValueDropdown then the custom object will show in the dropdown, let me select an object, but not save. If I try to use the dropdown on a list item I get an error where Odin is passing an empty object to my == override.

For example,

[Serializable]

public class WorldSortingLayers : Enumberation
{
  int ID;
  LayerMask layerMask;
  string Name;

  public static List<WorldSortingLayers> Layers = new List<WorldSortingLayers>(); #constructor auto adds entities

  #Example entry
  public static WorldSortingLayers Water { get; } = new WorldSortingLayers(4, LayerMask.NameToLayer("Water"), "4.Water");

  ...
}

---
[Serializable]

public class bla : ScriptableObject

  # Not having ValueDropdown makes it so that the list shows in the inspector, but it doesn't list any objects.
  # ValueDropdown with GetAllWorldObjects allows me to select an object but it doesn't save when I close.
  # It also causes "NullReferenceException: Object reference not set to an instance of an object" error when I select the dropdown on a list item
  [ValueDropdown("GetAllWorldObjects")] 
  public WorldSortingLayers[] LayersToGenerate; #I've tried List<WorldSortingLayers> as well

  private static IEnumerable GetAllWorldObjects()
  {
      return WorldSortingLayers.Layers;
  }

How can we reproduce it?

Use the code above.

If screenshots would help explain or demonstrate your issue, please include these.

Without ValueDropdown:

Note how the array items cannot be listed. This is expected since I don’t tell ValueDropdown what to display.

With ValueDropdown and GetAllWorldObjects:

After closing Unity:

When selecting the v dropdown beside Ground:

What version of Unity are you using?

2022.1.12f1

What version of Odin are you using? (See "Tools > Odin Inspector > About")

3.0.9.0

Do you have Editor Only mode enabled?

No

What operating system are you on?

Windows 11 and Mac

The == error:

NullReferenceException: Object reference not set to an instance of an object
Beyond.Utilities.Utilities.Enumeration.op_Equality (Beyond.Utilities.Utilities.Enumeration a, Beyond.Utilities.Utilities.Enumeration b) (at Assets/Scripts/X. Utilities/Enumeration.cs:46)
Beyond.Utilities.Utilities.Enumeration.Equals (System.Object obj) (at Assets/Scripts/X. Utilities/Enumeration.cs:35)
System.Collections.Generic.ObjectEqualityComparer`1[T].Equals (T x, T y) (at <2a5238bf45b34fd9a0fa6c4215e0c8ba>:0)
Sirenix.OdinInspector.Editor.Drawers.IValueDropdownEqualityComparer.Equals (System.Object x, System.Object y) (at <c685239a06de40df8fecff98c002a442>:0)
Sirenix.OdinInspector.Editor.Drawers.ValueDropdownAttributeDrawer+<>c__DisplayClass19_1.<CreateSelector>b__3 (Sirenix.OdinInspector.ValueDropdownItem c) (at <c685239a06de40df8fecff98c002a442>:0)
System.Collections.Generic.List`1[T].RemoveAll (System.Predicate`1[T] match) (at <2a5238bf45b34fd9a0fa6c4215e0c8ba>:0)
Sirenix.OdinInspector.Editor.Drawers.ValueDropdownAttributeDrawer+<>c__DisplayClass19_0.<CreateSelector>b__2 (System.Object x) (at <c685239a06de40df8fecff98c002a442>:0)
Sirenix.Utilities.LinqExtensions.ForEach[T] (System.Collections.Generic.IEnumerable`1[T] source, System.Action`1[T] action) (at <44981eca01194a5e927121a6fa329049>:0)
Sirenix.OdinInspector.Editor.Drawers.ValueDropdownAttributeDrawer.CreateSelector () (at <c685239a06de40df8fecff98c002a442>:0)
Sirenix.OdinInspector.Editor.Drawers.ValueDropdownAttributeDrawer.ShowSelector (UnityEngine.Rect rect) (at <c685239a06de40df8fecff98c002a442>:0)
Sirenix.OdinInspector.Editor.OdinSelector`1[T].DrawSelectorDropdown (UnityEngine.GUIContent label, UnityEngine.GUIContent btnLabel, System.Func`2[T,TResult] createSelector, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at <c685239a06de40df8fecff98c002a442>:0)
Sirenix.OdinInspector.Editor.OdinSelector`1[T].DrawSelectorDropdown (UnityEngine.GUIContent label, System.String btnLabel, System.Func`2[T,TResult] createSelector, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at <c685239a06de40df8fecff98c002a442>:0)
Sirenix.OdinInspector.Editor.Drawers.ValueDropdownAttributeDrawer.DrawDropdown () (at <c685239a06de40df8fecff98c002a442>:0)
Sirenix.OdinInspector.Editor.Drawers.ValueDropdownAttributeDrawer.DrawPropertyLayout (UnityEngine.GUIContent label) (at <c685239a06de40df8fecff98c002a442>:0)
Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (UnityEngine.GUIContent label) (at <c685239a06de40df8fecff98c002a442>:0)
Sirenix.OdinInspector.Editor.Drawers.TooltipAttributeDrawer.DrawPropertyLayout (UnityEngine.GUIContent label) (at <c685239a06de40df8fecff98c002a442>:0)
Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (UnityEngine.GUIContent label) (at <c685239a06de40df8fecff98c002a442>:0)
Sirenix.OdinInspector.Editor.Drawers.FixUnityNullDrawer`1[T].DrawPropertyLayout (UnityEngine.GUIContent label) (at <c685239a06de40df8fecff98c002a442>:0)
Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (UnityEngine.GUIContent label) (at <c685239a06de40df8fecff98c002a442>:0)
Sirenix.OdinInspector.Editor.Drawers.ReferenceDrawer`1[T].DrawPropertyLayout (UnityEngine.GUIContent label) (at <c685239a06de40df8fecff98c002a442>:0)
Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (UnityEngine.GUIContent label) (at <c685239a06de40df8fecff98c002a442>:0)
Sirenix.OdinInspector.Editor.Drawers.PropertyContextMenuDrawer`1[T].DrawPropertyLayout (UnityEngine.GUIContent label) (at <c685239a06de40df8fecff98c002a442>:0)
Sirenix.OdinInspector.Editor.OdinDrawer.DrawProperty (UnityEngine.GUIContent label) (at <c685239a06de40df8fecff98c002a442>:0)
Sirenix.OdinInspector.Editor.InspectorProperty.Draw (UnityEngine.GUIContent defaultLabel) (at <c685239a06de40df8fecff98c002a442>:0)
Rethrow as OdinPropertyException: This error occurred while being drawn by Odin.
Current IMGUI event: Used
Odin Property Path: _caveTile.LayersToGenerate.$0
Odin Drawer Chain:
> PropertyContextMenuDrawer<WorldSortingLayers>
> ReferenceDrawer<WorldSortingLayers>
> FixUnityNullDrawer<WorldSortingLayers>
> TooltipAttributeDrawer
> ValueDropdownAttributeDrawer
> NullableReferenceDrawer<WorldSortingLayers>
> CompositeDrawer.
UnityEngine.Debug:LogException(Exception)
Sirenix.OdinInspector.Editor.InspectorProperty:Draw(GUIContent)
Sirenix.OdinInspector.Editor.Drawers.CollectionDrawer`1:DrawItem(InspectorProperty, DragHandle, Color, Color)
Sirenix.OdinInspector.Editor.Drawers.CollectionDrawer`1:DrawItems()
Sirenix.OdinInspector.Editor.Drawers.CollectionDrawer`1:DrawPropertyLayout(GUIContent)
Sirenix.OdinInspector.Editor.OdinDrawer:CallNextDrawer(GUIContent)
Sirenix.OdinInspector.Editor.Drawers.NullableReferenceDrawer`1:DrawPropertyLayout(GUIContent)
Sirenix.OdinInspector.Editor.OdinDrawer:CallNextDrawer(GUIContent)
Sirenix.OdinInspector.Editor.Drawers.ValueDropdownAttributeDrawer:DrawPropertyLayout(GUIContent)
Sirenix.OdinInspector.Editor.OdinDrawer:CallNextDrawer(GUIContent)
Sirenix.OdinInspector.Editor.Drawers.TooltipAttributeDrawer:DrawPropertyLayout(GUIContent)
Sirenix.OdinInspector.Editor.OdinDrawer:CallNextDrawer(GUIContent)
Sirenix.OdinInspector.Editor.Drawers.FixUnityNullDrawer`1:DrawPropertyLayout(GUIContent)
Sirenix.OdinInspector.Editor.OdinDrawer:CallNextDrawer(GUIContent)
Sirenix.OdinInspector.Editor.Drawers.ReferenceDrawer`1:DrawPropertyLayout(GUIContent)
Sirenix.OdinInspector.Editor.OdinDrawer:CallNextDrawer(GUIContent)
Sirenix.OdinInspector.Editor.Drawers.PropertyContextMenuDrawer`1:DrawPropertyLayout(GUIContent)
Sirenix.OdinInspector.Editor.OdinDrawer:DrawProperty(GUIContent)
Sirenix.OdinInspector.Editor.InspectorProperty:Draw(GUIContent)
Sirenix.OdinInspector.Editor.Drawers.CompositeDrawer:DrawPropertyLayout(GUIContent)
Sirenix.OdinInspector.Editor.OdinDrawer:CallNextDrawer(GUIContent)
Sirenix.OdinInspector.Editor.Drawers.HeaderAttributeDrawer:DrawPropertyLayout(GUIContent)
Sirenix.OdinInspector.Editor.OdinDrawer:CallNextDrawer(GUIContent)
Sirenix.OdinInspector.Editor.Drawers.PropertyContextMenuDrawer`1:DrawPropertyLayout(GUIContent)
Sirenix.OdinInspector.Editor.OdinDrawer:DrawProperty(GUIContent)
Sirenix.OdinInspector.Editor.InspectorProperty:Draw(GUIContent)
Sirenix.OdinInspector.Editor.InspectorProperty:Draw()
Sirenix.OdinInspector.Editor.Drawers.UnityObjectRootDrawer`1:DrawPropertyLayout(GUIContent)
Sirenix.OdinInspector.Editor.OdinDrawer:DrawProperty(GUIContent)
Sirenix.OdinInspector.Editor.InspectorProperty:Draw(GUIContent)
Sirenix.OdinInspector.Editor.PropertyTree:DrawProperties()
Sirenix.OdinInspector.Editor.PropertyTree:Draw(Boolean)
Sirenix.OdinInspector.Editor.OdinEditor:DrawTree()
Sirenix.OdinInspector.Editor.OdinEditor:DrawOdinInspector()
Sirenix.OdinInspector.Editor.OdinEditor:OnInspectorGUI()
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)

Comments (1)

  1. Log in to comment