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

IVisualElementComponent

interface 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

The interface for all UI Toolkit component structs.

You don't implement this interface yourself: when you declare a partial struct with the VisualElementComponentAttribute, Unity's source generator adds the interface to the generated part of the struct. The interface is an implementation detail of that generator: its members are not a stable API, and Unity can add, change, or remove them in any version. The component methods on VisualElement, such as VisualElement.AddComponent, accept any struct that has it. The hooks are emitted by the source generator, never written by hand. They let AddComponent / RemoveComponent (un)register a component's [RegisterCallback] handlers and validate its [RequiresElementOfType] owner constraint through a constrained generic call, resolved by the compiler, so there is no reflection and no boxing of the component struct. A component that declares no callbacks (or no owner constraint) gets empty generated bodies. The storage hot path (GetComponent) never calls these, so it is unaffected.