Search Unity

Using dropdowns, or choice fields

Discussion in 'UI Toolkit' started by rogerdv, Nov 15, 2019.

  1. rogerdv

    rogerdv

    Joined:
    Jul 16, 2012
    Posts:
    90
    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.
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    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.
     
  3. rogerdv

    rogerdv

    Joined:
    Jul 16, 2012
    Posts:
    90
    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.
     
  4. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    See Window > UI > UIElements Samples >> Choice Fields > PopupField for a quick sample on how to use PopupField from code.
     
    Nowak_ITK likes this.