Version: Unity 6 (6000.0)
Language : English
Define a data source for runtime binding
Convert data types

Define binding mode and update trigger

To define how changes are replicated between the data source and the UI(User Interface) Allows a user to interact with your application. Unity currently supports three UI systems. More info
See in Glossary
, you can set the binding mode and update triggers for a binding object. You can set the binding mode and update triggers in UI Builder, UXML, or C#.

Define binding modes

Binding modes configure how changes are replicated between the data source and the UI. The following binding modes are available:

  • TwoWay: Changes are replicated from the data source to the UI and from the UI to the data source. This is the default binding mode.
  • ToTarget: Changes are replicated from the data source to the UI only.
  • ToSource: Changes are replicated from the UI to the data source only.
  • ToTargetOnce: Changes are replicated from the data source to the UI only once, unless it’s marked as dirty.

Tip: Ensure that you set the appropriate binding mode based on your needs. For example, to prevent changes in the UI from being reflected in the source or if the UI is read-only, set the bindingMode to BindingMode.ToTarget.

Define update triggers

You can update binding objects on every frame or when a change occurs in the data source. The following update triggers are available:

  • Every frame
  • On change detection or every frame if change detection is impossible. Refer to Define data sources for more details.
  • When explicitly marked as dirty

To define update triggers, use the following properties:

  • MarkDirty: Sets the binding object as dirty, so that it gets updated during the next cycle.
  • updateTrigger: Updates a binding object on every frame, regardless of the data source version.

Note: Don’t keep binding types per-element state. You can use a binding instance across multiple elements and properties simultaneously. During updates and callbacks, the binding system passes in a context object that contains the target element, binding ID, and relevant data. You can use this context object to store the per-element state.

Additional resources

Define a data source for runtime binding
Convert data types
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961