RequiresElementOfTypeAttribute
Restricts a VisualElementComponentAttribute component to a specific VisualElement subclass (or any class derived from it). When present, every [RegisterCallback] static method on the component may declare its owner parameter as the constrained type instead of plain VisualElement, and the component picker filters by the constraint.
Read time 4 minutesLast updated 6 days ago
Definition
- Type: Class
- Namespace: UnityEngine.UIElements
- Assembly: UnityEngine.UIElementsModule
- Inherits from: Attribute
[AttributeUsage(AttributeTargets.Struct, Inherited = false)]public sealed class RequiresElementOfTypeAttribute : Attribute
Remarks
The constraint is validated cheapest-first: a Roslyn analyzer on statically-known calls, generator validation of handler signatures, an runtime check, and a UXML import check. A struct may carry at most one RequiresElementOfTypeAttribute, and RequiresElementOfTypeAttribute.ElementType must be VisualElement or a subclass (anything else, including interfaces, is a compile-time error, UITKSG034).
AddComponent<T>()AddComponent<T>()Constructors
Constructor | Description |
|---|---|
| RequiresElementOfTypeAttribute(System.Type) | Initializes the attribute with the required owner element type. |
Properties
Property | Description |
|---|---|
| ElementType | The VisualElement subclass a component of this type may attach to. |