Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug DropdownField missing 'choices' property/field

Discussion in 'UI Toolkit' started by Dipity, Apr 10, 2021.

  1. Dipity

    Dipity

    Joined:
    Nov 8, 2016
    Posts:
    17
    Hi,

    it seems that the DropdownField class is missing the 'choices' property.

    According to the example we should be able to find the dropdown field in the UXML tree and then be able to set the choices value:
    Code (CSharp):
    1. // Get a reference to the dropdown field from UXML and assign it its value.
    2. var uxmlField = container.Q<DropdownField>("the-uxml-field");
    3. uxmlField.choices = choices;
    4. uxmlField.value = choices[0];
    Currently the only way is to create the DropdownField in c# and set the choices list directly in the constructor.

    Edit: So I was looking at the wrong cs file of Dropdownfield, it does have a choices property but it's seems it's not exposing it, so you can't set/get it.

    The Scripting API also shows no sign of a choices property:
    https://docs.unity3d.com/Packages/com.unity.ui@1.0/api/UnityEngine.UIElements.DropdownField.html

    Tested in Unity 2021.1.1f & 2021.1.2f, trying to use it for a custom inspector.
     
    Last edited: Apr 10, 2021
  2. sebastiend-unity

    sebastiend-unity

    Unity Technologies

    Joined:
    Nov 9, 2015
    Posts:
    183
    Hi,
    Thanks. This is a known limitation and is already on our grocery list :) We will make sure it is added as soon as possible.

    Sebastien
     
    Leslie-Young likes this.
  3. Dipity

    Dipity

    Joined:
    Nov 8, 2016
    Posts:
    17
    Hi,

    thx for the response, good to know, so I won't file this as a bug :)
     
    sebastiend-unity likes this.
  4. CxydaIO

    CxydaIO

    Joined:
    May 12, 2014
    Posts:
    51
    omg, really? I mean REALLY?
    I can use the UIBuilder to build my UI using Dropdown fields and then i cannot fill it programmatically with choices because the choices field is internal?
     
  5. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    732
    This is fixed in 2021.2. Which version are you using?
     
    CxydaIO likes this.
  6. CxydaIO

    CxydaIO

    Joined:
    May 12, 2014
    Posts:
    51
    Ah! Great! Thanks for response! I'm using latest 2021 (2021.1.15).

    Upgrading now!
     
  7. CxydaIO

    CxydaIO

    Joined:
    May 12, 2014
    Posts:
    51
    Are there any plans to backport the fix to 2021 ?
     
  8. mfolsom

    mfolsom

    Joined:
    May 21, 2016
    Posts:
    5
    I mean, the surprises I keep finding with this UIBuilder UIToolkit has brought me to the point of questioning why am I bothering multiple multiple x 10 times.

    Is UIToolkit / Builder / Runtime support really going to be functional when 2021 comes out? This is a serious question as I am planning on releasing making use of .uss/ .uxml as it opens up the UI coding to web devs.

    Updating to latest alpha and edited rant, but it has been a frustrating process.
     
    Last edited: Aug 18, 2021
  9. mahu

    mahu

    Joined:
    Apr 6, 2014
    Posts:
    8
    Isn't it possible to fix the issue in the package only? So we don't have to upgrade the whole project to another engine version, possibly causing some issues in the process.

    I'm using 2021.1.19f1 and I wouldn't like to change to a beta version.

    Would be great if that option was available.
     
  10. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    732
    I'll pass along that request to the team, but I can't guarantee anything. Ultimately 2021.2 is the recommended path forward as this is where most the effort will go for stability. Note that you won't need the package anymore in this version.
     
    mahu likes this.
  11. Cuongdd

    Cuongdd

    Joined:
    Apr 16, 2013
    Posts:
    3
    I have upgraded to 2021.2.2f1, and now i can see choices in the dropdownfield, but i dont know how to make it work with code, when i fill option with the code, and set value (select option) in the code, it doesn't work :(
     
  12. raymondyunity

    raymondyunity

    Unity Technologies

    Joined:
    Apr 30, 2018
    Posts:
    120
    It's working in 2021.2.2f1 the sample code above should work just fine
     
  13. Cuongdd

    Cuongdd

    Joined:
    Apr 16, 2013
    Posts:
    3
    yep, now i can do it when calling at LateUpdate() or after LateUpdate(). But when i want fill data at Start() function, it doesn't work.
     
  14. The_ZayNepz_Guy

    The_ZayNepz_Guy

    Joined:
    Mar 2, 2020
    Posts:
    5
    I'm having this issue now, where Visual Studio can't recognize the part "container" in the script. Any idea?