Search Unity

  1. How can our website serve you better? Give us your feedback. Take our survey and let us know.
    Dismiss Notice

Bug PopupField fails for enum with index > 0

Discussion in 'UI Toolkit' started by Araj, Oct 26, 2020.

  1. Araj

    Araj

    Joined:
    Jan 3, 2013
    Posts:
    27
    Hi!

    I have a custom Editor created with UI Toolkit and just found that when I'm creating the PropertyFields for my editors, if one of the SerializedProperties is an enum and that enum starts at index 1, the inspector gives a script error:

    Code (CSharp):
    1.  
    2. ArgumentException: Default Index  is beyond the scope of possible value
    3. UnityEditor.UIElements.PopupField`1[T]..ctor (System.String label, System.Collections.Generic.List`1[T] choices, System.Int32 defaultIndex, System.Func`2[T,TResult] formatSelectedValueCallback, System.Func`2[T,TResult] formatListItemCallback) (at <e6e2fa0a47414cd2ac33237924761b45>:0)
    4. UnityEditor.UIElements.PopupField`1[T]..ctor (System.Collections.Generic.List`1[T] choices, System.Int32 defaultIndex, System.Func`2[T,TResult] formatSelectedValueCallback, System.Func`2[T,TResult] formatListItemCallback) (at <e6e2fa0a47414cd2ac33237924761b45>:0)
    5. UnityEditor.UIElements.PropertyField.CreateFieldFromProperty (UnityEditor.SerializedProperty property) (at <e6e2fa0a47414cd2ac33237924761b45>:0)
    6. UnityEditor.UIElements.PropertyField.Reset (UnityEditor.UIElements.SerializedPropertyBindEvent evt) (at <e6e2fa0a47414cd2ac33237924761b45>:0)
    7. UnityEditor.UIElements.PropertyField.ExecuteDefaultActionAtTarget (UnityEngine.UIElements.EventBase evt) (at <e6e2fa0a47414cd2ac33237924761b45>:0)
    8. UnityEngine.UIElements.CallbackEventHandler.HandleEvent (UnityEngine.UIElements.EventBase evt) (at <356f1ddb1d524ad59c7a2c95775bb38e>:0)
    9.  
    Example enum
    Code (CSharp):
    1.         public enum EnumThatFails
    2.         {
    3.             Thing_1 = 1,
    4.             Thing_2 = 2,
    5.             Thing_3 = 3
    6.         }
    7.  
    8.         public EnumThatFails enumThatFails;
     
  2. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    323
    Hello! Can you submit a bug report through the Unity Editor? Thanks!
     
unityunity