Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


OnComponentAddedAttribute

Declares a static method of a VisualElementComponentAttribute struct that runs once, right after the component is added to an element.
Read time 4 minutesLast updated 6 days ago

Definition

[AttributeUsage(AttributeTargets.Method, Inherited = false)]public class OnComponentAddedAttribute : Attribute

Remarks

The method must be
static void M(ref T self, <see cref="UnityEngine.UIElements.VisualElement"></see> owner)
, and a component may declare at most one. It runs on every add path:
AddComponent
,
GetOrAddComponent
, a component authored in UXML, and a [RequiresComponentOfType] auto-add. It runs after the component is stored and its
[RegisterCallback]
handlers are registered, so the method sees a fully wired component and may configure the owner element (for example set
owner.focusable
). On the UXML path it runs when the component is created, before the authored attribute values are applied, so authored values always win over values this method writes to the component.

Inheritance

Inherited Members