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

RequiresComponentOfTypeAttribute

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 that a component needs another component type on the same element. When the declaring component is added to an element, from code or from UXML, the required components are added first, in declaration order. A required component that is already attached keeps its values. A required component that is missing is added with its default values.

The required type must be a struct decorated with VisualElementComponentAttribute. Requirements must not form a cycle: a component cannot require itself, directly or through other components. Both cases are compile-time errors. Removing a component that another attached component still requires is allowed; the editor logs a warning, player builds do no check.

Properties

Property Description
ComponentTypeThe component type that must exist on the same element.

Constructors

Constructor Description
RequiresComponentOfTypeAttributeInitializes the attribute with the required component type.