Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


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

[AttributeUsage(AttributeTargets.Struct, Inherited = false)]public sealed class RequiresElementOfTypeAttribute : Attribute

Remarks

The constraint is validated cheapest-first: a Roslyn analyzer on statically-known
AddComponent<T>()
calls, generator validation of handler signatures, an
AddComponent<T>()
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).

Constructors

Constructor

Description

RequiresElementOfTypeAttribute(System.Type)Initializes the attribute with the required owner element type.

Properties

Property

Description

ElementTypeThe VisualElement subclass a component of this type may attach to.

Inheritance

Inherited Members