Using dropdowns, or choice fields

How can I fill the values of dropdowns, named as choice fields in UI Builder? I have been looking at builder and cant find any way to add values, and neither from code.

Dropdowns, specifically, don’t have support for UXML at the moment. This is mostly because they are generic C# types and we don’t have support for generics in UXML right now. Since it can’t be instantiated in UXML, it also cannot be used in the UI Builder. The UI Builder can only create elements that can be represented in UXML (otherwise you would lose these elements when you exit Unity). It’s something we’re hoping to fix but for now you’ll have to stick to creating them in code. You can still create a “container” element in the UI Builder that is easy to find via query in C# once the UI is cloned.

How do I create them in code? Yesterday I spent some time looking for them in the help and trying names, but could not find them.

See Window > UI > UIElements Samples >> Choice Fields > PopupField for a quick sample on how to use PopupField from code.

1 Like