Delayed Reflection of DropdownField Changes in Unity 2022.3.28f1: Specification Change or Bug?

In Unity 2022.3.28f1, changes to DropdownField choices during a PointerDownEvent are not reflected when the dropdown is expanded. In Unity 2021.3.29f1, changes were immediate. Is this a specification change or a bug?

Sounds like it could be a bug. Could you please file a bug report? Unity QA: Building quality with passion

Thank you for the quick response. I’ll file a bug report. In the meantime, do you have any suggestions for making the dropdown update immediately during a PointerDownEvent?

Its hard to give a workaround without knowing what changed.
Can you show the code that was working but is not now?

Thank you for your assistance. Below is the code that was working in Unity 2021.3.29f1 but is not updating the dropdown immediately in Unity 2022.3.28f1:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class TestDropdownText : MonoBehaviour
{
    [SerializeField]
    private UIDocument m_UIDocument = null;

    private DropdownField DropdownField_Test = null;

    // Start is called before the first frame update
    void Start()
    {
        DropdownField_Test = m_UIDocument.rootVisualElement.Q<DropdownField>("DropdownField_Test");

        DropdownField_Test.RegisterCallback<PointerDownEvent>(OnPointerDown_DropdownField_Test);

        DropdownField_Test.choices.Add("Option A");

        DropdownField_Test.SetValueWithoutNotify("Option A");
    }

    // Update is called once per frame
    void Update()
    {
      
    }

    private void OnPointerDown_DropdownField_Test(PointerDownEvent evt)
    {
        DropdownField_Test.choices.Clear();

        DropdownField_Test.choices.Add("Option A");
        DropdownField_Test.choices.Add("Option B");
        DropdownField_Test.choices.Add("Option C");
        DropdownField_Test.choices.Add("Option D");
    }
}

In Unity 2021.3.29f1, this code would update the dropdown choices immediately when it is clicked. However, in Unity 2022.3.28f1, the dropdown doesn’t reflect the updated choices until it is closed and reopened.

We changed from using MouseDownEvent to navigation events in 2022.
Try using the NavigationSubmitEvent instead.
No need for a bug report now, it was an intentional change.

Thank you for your response.

I modified the code based on this page:

Additionally, I added a Button for testing.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class TestDropdownText : MonoBehaviour
{
    [SerializeField]
    private UIDocument m_UIDocument = null;

    private DropdownField DropdownField_Test = null;

    // Start is called before the first frame update
    void Start()
    {
        DropdownField_Test = m_UIDocument.rootVisualElement.Q<DropdownField>("DropdownField_Test");

        DropdownField_Test.RegisterCallback<NavigationSubmitEvent>(OnNavigationSubmit_DropdownField_Test);

        var Button_Test = m_UIDocument.rootVisualElement.Q<Button>("Button_Test");
        Button_Test.RegisterCallback<NavigationSubmitEvent>(OnNavigationSubmit_DropdownField_Test);

        DropdownField_Test.choices.Add("Option A");

        DropdownField_Test.SetValueWithoutNotify("Option A");
    }

    // Update is called once per frame
    void Update()
    {
       
    }

    //private void OnPointerDown_DropdownField_Test(PointerDownEvent evt)
    private void OnNavigationSubmit_DropdownField_Test(NavigationSubmitEvent evt)
    {
        Debug.Log("submit");

        DropdownField_Test.choices.Clear();

        DropdownField_Test.choices.Add("Option A");
        DropdownField_Test.choices.Add("Option B");
        DropdownField_Test.choices.Add("Option C");
        DropdownField_Test.choices.Add("Option D");
    }
}

When I ran the code, the NavigationSubmitEvent was not triggered by a mouse click. It only fired when pressing Enter after expanding the DropdownField. However, registering a Callback to the DropdownField caused this error:
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Pressing Enter on the Button triggered the Callback correctly.

Is this the proper way to use the NavigationSubmitEvent?

Ah sorry I only gave you 1 of the events we use, we also use PointerDownEvent and PointerMoveEvent

So

  • NavigationSubmitEvent

  • PointerDownEvent

  • PointerMoveEvent when left mouse button is held

Thank you for your response.

Using PointerMoveEvent and PointerEnterEvent, I resolved the issue where changes to the choices weren’t reflected when the DropdownField was first expanded.
This issue couldn’t be resolved with PointerDownEvent, NavigationSubmitEvent, or combining PointerMoveEvent with holding the left mouse button.

I suspect a delay of at least one frame between changing the choices and their reflection in the Dropdown options.

I chose to use PointerEnterEvent.

Thank you for your assistance.

1 Like