UxmlAttributeField
An Editor-only control that displays a serialized UXML attribute in the Inspector, with override indicators and binding affordances.
Read time 9 minutesLast updated 8 days ago
Definition
- Type: Class
- Namespace: Unity.UIToolkit.Editor
- Assembly: UnityEditor
- Inherits from: VisualElement
- Implements: IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, ICustomStyle
[UxmlElement]public class UxmlAttributeField : VisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, ICustomStyle
Remarks
Use UxmlAttributeField when you build custom drawers that derive from UxmlSerializedDataPropertyDrawer, so your fields match the auto-generated Inspector. The control shows the current attribute state: default, set inline, overridden in a template instance, or driven by a data binding.
When you don't set _label, it falls back to the display name of the bound SerializedProperty.
Additional Resources: UxmlAttributeFieldDecorator, UxmlSerializedDataPropertyDrawer
The following example creates a field bound to a property from inside a drawer.
FindPropertyRelativeExamples
var textProperty = property.FindPropertyRelative("text");if (textProperty != null){ var field = new UxmlAttributeField(textProperty); field.label = "Text Content"; container.Add(field);}
Static Fields
Value | Description |
|---|---|
| ussClassName | The USS class name for a UXML attribute field. |
Constructors
Constructor | Description |
|---|---|
| UxmlAttributeField() | Creates an unbound field. Set _bindingPath to bind it to a serialized property. |
| UxmlAttributeField(UnityEditor.SerializedProperty) | Creates a field bound to the given serialized property. |
Properties
Property | Description |
|---|---|
| bindingPath | The binding path of the serialized property this field displays and edits. |
| decorator | The decorator that draws the override indicator bar, binding affordances, and context menu for this field. |
| label | The label shown next to the field's input control. |