Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


RequiresComponentOfTypeAttribute

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.
Read time 4 minutesLast updated 6 days ago

Definition

[AttributeUsage(AttributeTargets.Struct, AllowMultiple = true, Inherited = false)]public sealed class RequiresComponentOfTypeAttribute : Attribute

Remarks

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.

Constructors

Constructor

Description

RequiresComponentOfTypeAttribute(System.Type)Initializes the attribute with the required component type.

Properties

Property

Description

ComponentTypeThe component type that must exist on the same element.

Inheritance

Inherited Members