A UxmlAttributeField is an Editor-only control that displays a serialized UXML attribute property in the Inspector with override indicators and binding affordances.
Use UxmlAttributeField when building custom property drawers that inherit from UxmlSerializedDataPropertyDrawer to maintain visual consistency with the auto-generated Inspector UI.
You can create a UxmlAttributeField in C# or UXML.
To create a UxmlAttributeField in C# and bind it to a SerializedProperty:
using Unity.UIToolkit.Editor;
using UnityEditor;
using UnityEngine.UIElements;
// Inside a UxmlSerializedDataPropertyDrawer override:
protected override void CreateChildPropertiesGUI(VisualElement container, SerializedProperty property)
{
var colorProperty = property.FindPropertyRelative("color");
if (colorProperty != null)
{
var field = new UxmlAttributeField(colorProperty);
// The label defaults to the display name of the serialized field.
// Set label explicitly to override it.
field.label = "Button Color";
container.Add(field);
}
}
To create a UxmlAttributeField in UXML, use the binding-path attribute to specify which property to display:
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uitke="Unity.UIToolkit.Editor">
<uitke:UxmlAttributeField binding-path="color" label="Button Color" />
</ui:UXML>
C# class: UxmlAttributeField
Namespace: Unity.UIToolkit.Editor
Base class: VisualElement
This element has the following member attributes:
| Name | Type | Description |
|---|---|---|
label |
string |
The label displayed next to the field. When not set, the label is derived from the bound property’s display name. |
binding-path |
string |
The path of the serialized property to bind and display. |
This element inherits UXML attributes from VisualElement.
| C# property | USS selector | Description |
|---|---|---|
ussClassName |
.unity-uxml-attribute-field |
USS class name applied to every UxmlAttributeField instance. |
You can also use the Matching Selectors section in the Inspector or the UI Toolkit Debugger to see which USS selectors affect the components of the VisualElement at every level of its hierarchy.