Skip to content

Component & Class Attributes

Component behavior, execution and type migration in Unity.

Reference baseline: Unity 6.0 API; Burst entries use the Burst 1.8 manual. Namespaces and placement are requirements, not claims about the first supported Unity version.

Attribute fragments belong on the declaration described by their requirements; alternatives are shown separately.

Place this component under a custom submenu.

[AddComponentMenu("DevHints/Example")]

Requirements: UnityEngine; MonoBehaviour-derived class.

Primary documentation

Prevent duplicates of this component on one GameObject.

[DisallowMultipleComponent]

Requirements: UnityEngine; MonoBehaviour-derived class.

Primary documentation

Useful for managers or controllers that should be unique on an object.

Automatically add the required component when this component is added to a GameObject. Dependencies are checked at addition time; changing the attribute does not retrofit existing instances.

[RequireComponent(typeof(Rigidbody))]

Requirements: UnityEngine; MonoBehaviour-derived class; Component type.

Primary documentation

Run this MonoBehaviour in Edit mode.

[ExecuteInEditMode]

Requirements: UnityEngine; MonoBehaviour-derived class.

Primary documentation

Prefer ExecuteAlways for code that explicitly handles Prefab Mode. Keep editor-only APIs separate from player code.

Run MonoBehaviour callbacks in Edit Mode and Prefab Mode as well as during normal play. Callback frequency outside the playing world differs from Play Mode.

[ExecuteAlways]

Requirements: UnityEngine; MonoBehaviour-derived class.

Primary documentation

Guard runtime-only behavior with Application.IsPlaying(gameObject) so editing a prefab does not run playing-world logic. This attribute does not guarantee that disabled behaviours execute.

Scene-view clicks on children select this GameObject

[SelectionBase]

Requirements: UnityEngine; class attached to a GameObject.

Primary documentation

Handy for complex hierarchies like props with many sub-meshes.

Link the component Inspector’s help icon to a URL.

[HelpURL("https://example.com/component-help")]

Requirements: UnityEngine; class; documentation URL string.

Primary documentation

Control script execution order.

[DefaultExecutionOrder(-100)]

Requirements: UnityEngine; MonoBehaviour-derived class; constant integer order.

Primary documentation

Mark an assembly so Unity considers its classes to be editor classes. This attribute targets the assembly, not an individual class.

[assembly: AssemblyIsEditorAssembly]

Requirements: UnityEngine; assembly target.

Primary documentation

Do not treat this marker alone as a general guarantee about player-build inclusion; editor assembly and compilation settings still matter.

Record a type’s previous namespace to help preserve serialized references after a move. The simple constructor takes the old namespace; more detailed constructors can identify the old assembly and class.

[MovedFrom("Old.Namespace")]

Requirements: UnityEngine.Scripting.APIUpdating; supported type declaration.

Primary documentation

Serialization migration and API updating have different limits. The API updater does not generally repair arbitrary class-name or assembly moves; check the documented constructor behavior before relying on it.