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

OnComponentAddedAttribute

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

Declares a static method of a VisualElementComponentAttribute struct that runs once, right after the component is added to an element.

The method must be @@static void M(ref T self, VisualElement 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.