Version: 2023.2
Customize UXML tag names and attributes
Define a namespace prefix

Bind custom controls to data

You bind custom controls to serialized properties to synchronize values between the control and the property. You can create a bindable custom control derived from the BaseField generic base class instead of BindableElement. This provides the following advantages:

  • Implements the INotifyValueChanged interface for the generic parameter type that you specify.
  • Makes the control focusable by default.
  • Provides a horizontal layout with a label element on the left and input on the right.
FloatField is a built-in UI Toolkit control which inherits from BaseField.<br/>A. The label element.<br/>B. The input element.
FloatField is a built-in UI Toolkit control which inherits from BaseField.
A. The label element.
B. The input element.

Note: It’s possible to create custom controls derived from built-in UI controls if you understand their internal hierarchy and existing USS classes. Unity discourages this practice because your custom controls might be dependent on their internal structure, which is subject to change in the future.

To bind custom controls to data:

Refer to SerializedObject data binding for more details.

For a bindable custom control example, refer to Create a bindable custom control.

其他资源

Customize UXML tag names and attributes
Define a namespace prefix