Binding
Configure one-way data binding from MonoBehaviour fields and properties to UI Toolkit controls.
ULB binding polls a readable field or property from a component and writes the value into a supported linked UI Toolkit element.
Binding in 3.0.1 is one-way: component to UI. Editing the UI control does not write a value back to the source member.
Supported binder components
- Text and scalar: UitkLabel, UitkTextField, UitkDoubleField, UitkFloatField, UitkIntegerField, UitkLongField, UitkEnumField.
- Controls: UitkProgressBar, UitkRadioButton, UitkSlider, UitkSliderInt.
- Vectors: UitkVector2Field, UitkVector2IntField, UitkVector3Field, UitkVector3IntField, UitkVector4Field.
- Visual content: UitkImage with a Sprite source.
Availability of a concrete binder depends on whether its UI Toolkit element type exists in the current Unity version.
Inspector setup
- Configure UIDocument, Linking Mode, and the element locator first.
- Enable Binding Enabled.
- Assign a GameObject to Binding > Target Object. The source component must be attached to that GameObject.
- Open the Member popup and select a readable field or property.
- Optionally assign a UitkBindingSettings asset to control the Member popup.
- Set Binding Rate Ms.
The stored member path uses slash-separated segments. The first segment is the component type name; the remaining segments are fields or readable properties, for example ValueUpdater/Player/Health.
Update rate
- If either Binding Rate Ms value is 0 or negative, the binding updates every Update call.
- If both positive values are equal, that value is the fixed interval in milliseconds.
- If both positive values differ, ULB chooses a new random interval between them after each update.
Use the slowest interval that still keeps the UI responsive. Every update reads the member chain and converts the value.
Programmatic setup
using DA_Assets.ULB;
using UnityEngine;
public sealed class HealthProvider : MonoBehaviour
{
public float Health = 100f;
}
public sealed class HealthBindingSetup : MonoBehaviour
{
[SerializeField] private UitkProgressBar healthBar;
[SerializeField] private HealthProvider provider;
private void Start()
{
healthBar.BindingEnabled = true;
healthBar.BindingRateMs = new Vector2Int(100, 100);
healthBar.Binding = new MemberBinding
{
TargetObject = provider.gameObject,
Member = $"{nameof(HealthProvider)}/{nameof(HealthProvider.Health)}"
};
healthBar.Initialize();
}
}Set the locator and binding fields before Initialize. Initialize links the element and caches the selected member chain.
How values are applied
- Bind resolves the component and caches the selected public, non-public, instance, or static field and property chain.
- Each update reads the cached chain. A null source value skips that UI update.
- ULB converts the source value to the bindable type declared by the linker.
- INotifyValueChanged<T> controls receive their value directly. ProgressBar and Image have dedicated handling; other targets use a value-property reflection fallback.
The source type must be compatible with the binder type. A failed conversion is logged and the previous UI value remains unchanged.
Binding settings
- Max Depth: maximum depth exposed by the Member popup, from 0 to 4.
- Show Primitive Type: adds primitive type names to popup labels.
- Show Object Type: adds class or value-type names to popup labels.
- Show To String: exposes [ToString] choices for supported Unity structs.
- Show Obsolete: includes obsolete members except members marked Obsolete with IsError = true.
UitkBindingSettings affects Member popup discovery and labels. It does not change the runtime update interval.
Show To String covers supported Unity types such as Color, Vector types, Rect, Bounds, Quaternion, and Matrix4x4. Verify that the selected value can be converted to the target binder type.
Change a binding at runtime
After changing TargetObject or Member, call Bind to rebuild the cached member chain. If the UIDocument tree or locator also changed, configure all fields and call Initialize.