Can't edit enum arrays in inspector with .NET 4.x

Issue #352 resolved
Former user created an issue

1. I use .NET 4.x in my project. I created an enum, then an enum array, and set in public to see it in the inspector. The array is uneditable, every action creates an error in the console (see at the end of post).

2. - Create a new project - Create an enum array, like this one, and put it on a GameObject:

using UnityEngine;

public class EnumArrayTest : MonoBehaviour
{
    public enum GermanicGod { Odin, Thor, Nerthus, Veleda, Tuisto, Mannus }
    public GermanicGod[] gods;
}
  • Play with it a bit, it works! Enums appear correctly.
  • Go to Edit > Project Settings > Player > Other Settings
  • Set Scripting Runtime Version to ".NET 4.x equivalent"
  • Check your object, the enum values have been replaced by their integer representation (see attached screenshot)
  • Try to add new entries, or change the order, it creates this error:

ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array. (wrapper stelemref) System.Object.virt_stelemref_sealed_class(intptr,object) Sirenix.OdinInspector.Editor.PropertyValueEntry`1[TValue].Sirenix.OdinInspector.Editor.IValueEntryActualValueSetter.SetActualValue (System.Int32 index, System.Object value) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Value Drawers/QuaternionDrawer.cs:89) Sirenix.OdinInspector.Editor.PropertyListValueEntryChanger.SetAllTreeActualValueReferences (System.Int32 index, System.Object value, System.Object newValue) (at <16b17155958448d5bd78b565329b0e7d>:0) Sirenix.OdinInspector.Editor.PropertyStrongListValueEntryChanger`2[TList,TElement].AddListElementImplementation (System.Object[] values) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/FixUnityNullDrawer.cs:38) Sirenix.OdinInspector.Editor.PropertyListValueEntryChanger.ApplyChanges () (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Attribute Drawers/RangeAttributeDrawer.cs:75) Sirenix.OdinInspector.Editor.PropertyValueEntry`2[TParent,TValue].ApplyChanges () (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Value Drawers/TypeDrawer.cs:25) Sirenix.OdinInspector.Editor.PropertyTree.ApplyChanges () (at <16b17155958448d5bd78b565329b0e7d>:0) Sirenix.OdinInspector.Editor.InspectorUtilities.EndDrawPropertyTree (Sirenix.OdinInspector.Editor.PropertyTree tree) (at <16b17155958448d5bd78b565329b0e7d>:0) Sirenix.OdinInspector.Editor.PropertyTree.Draw (System.Boolean applyUndo) (at <16b17155958448d5bd78b565329b0e7d>:0) Sirenix.OdinInspector.Editor.OdinEditor.DrawTree () (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Children/PropertyValueCollection.cs:541) Sirenix.OdinInspector.Editor.OdinEditor.DrawOdinInspector () (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Children/PropertyValueCollection.cs:533) Sirenix.OdinInspector.Editor.OdinEditor.OnInspectorGUI () (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Children/PropertyValueCollection.cs:516) UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor[] editors, System.Int32 editorIndex, System.Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1295) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

  1. Screenshot attached
  2. I'm using Unity 2018.1.1f1 64bits
  3. I'm using Odin 1.0.6.8
  4. I'm not in Editor only mode
  5. Windows 10

Note: I put this in Critical priority because I simply can't use enum arrays anymore.

Comments (9)

  1. Austin Renner

    I’m using Odin 2.1.8, .NET 2.0, Unity 2019.2.6f1 and I’m getting this exception every time I try to add an item to my enum array.

  2. Tor Esa Vestergaard
    • changed status to open

    I'm reopening the issue - seems something must have changed, we'll investigate. Thanks for the report!

  3. Janus Anderson

    Has anyone found a workaround for this? I upgraded to 2.1.8 and have many places in my project that use enum arrays, so I’m effectively unable to keep working until this is resolved or a workaround is found.

  4. Tor Esa Vestergaard

    After some investigation, I have discovered the factor that re-introduced the issue and developed a work-around for this. In short, MyEnum[] implements the IList<int> interface in newer versions of the Mono runtime for ineffable reasons, but it's not really allowed to be treated as an IList<int>. Odin detects this interface implementation instead of the correct IList<MyEnum> implementation, because it is earlier in the result array when typeof(MyEnum[]).GetInterfaces() is invoked, and so is matched on first. So the MyEnum[] type is faultily concluded to have an element type of “int” by Odin. I’ve added some code in relevant locations that detects this specific edge case for arrays and always locates the correct IList<MyEnum> interface implementation.

    This fix will be in the next release of Odin. Meanwhile, if anyone needs a fixed build, please contact me on Discord and I will send it to you.

  5. Log in to comment