Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


UxmlAttributeField

Read time 1 minuteLast updated a month ago

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.

A UxmlAttributeField in the Inspector showing a label and a value with override affordance

Create a UxmlAttributeField

You can create a
UxmlAttributeField
in C# or UXML.

Create with C#

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); }}

Create with UXML

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# base class and namespace

Namespace:
Unity.UIToolkit.Editor
Base class:
VisualElement

Member UXML attributes

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.

Inherited UXML attributes

This element inherits UXML attributes from
VisualElement
.

USS classes

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.

Additional resources