Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

RequiresElementOfTypeAttribute

class in UnityEngine.UIElements

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

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.

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).

Properties

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

Constructors

Constructor Description
RequiresElementOfTypeAttributeInitializes the attribute with the required owner element type.