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.
| Property | Description |
|---|---|
| ComponentType | The component type that must exist on the same element. |
| Constructor | Description |
|---|---|
| RequiresComponentOfTypeAttribute | Initializes the attribute with the required component type. |