Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


IVisualElementComponent

The interface for all UI Toolkit component structs.
Read time 1 minuteLast updated 4 days ago

Definition

public interface IVisualElementComponent

Remarks

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.