Search Unity

Binding

Discussion in 'UI Toolkit' started by Goooooooogle, Jun 15, 2019.

  1. Goooooooogle

    Goooooooogle

    Joined:
    Sep 30, 2016
    Posts:
    11
    Previously in Unity 2018, I can use dataWatch of a visual element to monitor some property and update the element, for example, I can watch a string URL property on a scriptableObject and fetch the content of that url and update the result in the element when the URL changes.

    since dataWatch is removed in the 2019, I wonder what the best way is to achieve the same effect. In the api migration guide, there's only one line that says "The dataWatch property was removed. This feature will not be available anymore. One can use SerializedProperty bindings instead."

    Any guidance is appreciated.
     
  2. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    780
    Hello,

    This page contains some information about the bindings feature:
    https://docs.unity3d.com/Manual/UIE-Binding.html

    In a few words, the overall recipe is:
    1. Create ScriptableObject type that holds your text property for example "m_URL"
    2. Create a TextField with the
      binding-path
      property to "m_URL"
    3. Add the TextField to a parent
    4. Create a SerializedObject targeting an instance of this object
    5. Call parent.Bind(serializedObject)
    This should set-up a two-way binding between the TextField and the scriptable object property.
     
    Goooooooogle likes this.