Delay in UI-Toolkit Databinding

A quick note on the UI toolkit’s data binding. If you access the bound data immediately after changing a field in the UI, this does not provide the current new value!
The waiting time is about 1 frame.
The following helped me:

    public void OnIntegerFieldChanged(ChangeEvent<int> changeEvent)
        {
            StartCoroutine(UseDataWithWaitForEndOfFrameDelay(changeEvent.newValue));
            //UseDataWithoutDelay(changeEvent.newValue);
        }

		void UseDataWithoutDelay (int newValue)  //Demonstrate the Problem
        {
            Debug.Log("DataValue: " + data.intNumber + "  FieldValue: " + newValue);
        }
		
		
		 IEnumerator UseDataWithWaitForEndOfFrameDelay(int newValue)  //This is working
        {
            yield return new WaitForEndOfFrame();
            Debug.Log("DataValue: " + data.intNumber + "  FieldValue: " + newValue);
        }

Greetings

That is indeed correct, the data binding ticks at the same time as the other UI Toolkit updaters. This is similar to the styles update, if you change the style.width of your element, the resolvedStyle.width will not be updated right away.

Hope this helps!

The binding set at the beginning of the frame will be processed before the GeometryChangedEvent event that is guarantee to be called the first time the object is visible. In that callback you are free to read the value and to modify any other value except binding and animation (both won’t be re-evalutated for the current frame)

I also think bindings will be processed before the LateUpdate if this is for a runtime panel, but I would have to verify.