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
- Type: Class
- Namespace: UnityEngine.UIElements
- Assembly: UnityEngine.UIElementsModule
- Inherits from: Attribute
[AttributeUsage(AttributeTargets.Method, Inherited = false)]public class OnComponentAddedAttribute : Attribute
Remarks
The method must be , and a component may declare at most one. It runs on every add path: , , a component authored in UXML, and a [RequiresComponentOfType] auto-add. It runs after the component is stored and its handlers are registered, so the method sees a fully wired component and may configure the owner element (for example set ). 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.
static void M(ref T self, <see cref="UnityEngine.UIElements.VisualElement"></see> owner)AddComponentGetOrAddComponent[RegisterCallback]owner.focusable