Search Issue Tracker


Fixed in 2021.3.36f1, 2022.3.22f1, 2023.2.13f1, 2023.3.0b11



Found in





Issue ID




Error thrown when selecting an item with an empty string in DropdownField



*Steps to reproduce:*
# create an editor window with ui toolkit with the following code:

var newDropdown = new DropdownField
choices = new List<string>()
}; {code}
2. view the window and select the second item from the dropdown (1)

3. select the first item (renders as an empty string)

*Actual results:* 

throws the following error
IndexOutOfRangeException: Index was outside the bounds of the array.
UnityEngine.UIElements.UIElementsUtility.ParseMenuName (System.String menuName) (at <7380b1ba6a1943f8acdb977b1081158a>:0)
UnityEngine.UIElements.PopupField`1[T].GetValueToDisplay () (at <7380b1ba6a1943f8acdb977b1081158a>:0)
UnityEngine.UIElements.BasePopupField`2[TValueType,TValueChoice].SetValueWithoutNotify (TValueType newValue) (at <7380b1ba6a1943f8acdb977b1081158a>:0)
UnityEngine.UIElements.PopupField`1[T].SetValueWithoutNotify (T newValue) (at <7380b1ba6a1943f8acdb977b1081158a>:0)
UnityEngine.UIElements.BaseField`1[TValueType].set_value (TValueType value) (at <7380b1ba6a1943f8acdb977b1081158a>:0)
UnityEngine.UIElements.PopupField`1[T].set_value (T value) (at <7380b1ba6a1943f8acdb977b1081158a>:0)
UnityEngine.UIElements.PopupField`1[T].ChangeValueFromMenu (T menuItem) (at <7380b1ba6a1943f8acdb977b1081158a>:0)
UnityEngine.UIElements.PopupField`1+<>c__DisplayClass27_0[T].<AddMenuItems>b__0 () (at <7380b1ba6a1943f8acdb977b1081158a>:0)
UnityEditor.GenericMenu.CatchMenu (System.Object userData, System.String[] options, System.Int32 selected) (at <c70b76c1ec924538944ac52fdfba807d>:0) {code}
*Expected results:* 

no error thrown, item is selected correctly.


From the discussion on slack, it sounds like allowing empty strings of any variety in the list is not allowed. I would expect in that case for this to throw an error much earlier, when setting the choices property. I'd also expect this behavior to be documented somewhere, I'm not seeing it here []


That said, I don't exactly understand why this design opinion is coming into the api - if a user wants to make a dropdown that is full of empty string, I'm not clear why we would make that impossible at the api level. It makes sense to include it in the design documentation.

*Reproducible with versions:* 2023.3.0b5 (dots monorepo currently)

*Not reproducible with versions:* I'm not sure of the specific version, but this is a regression - I believe the dots monorepo version from november doesn't have this issue.

*Can’t test with versions:* 

*Tested on (OS):* 


Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.