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.
AddComponentMenu
Section titled “AddComponentMenu”Place this component under a custom submenu.
[AddComponentMenu("DevHints/Example")]Requirements: UnityEngine; MonoBehaviour-derived class.
DisallowMultipleComponent
Section titled “DisallowMultipleComponent”Prevent duplicates of this component on one GameObject.
[DisallowMultipleComponent]Requirements: UnityEngine; MonoBehaviour-derived class.
Useful for managers or controllers that should be unique on an object.
RequireComponent
Section titled “RequireComponent”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.
ExecuteInEditMode
Section titled “ExecuteInEditMode”Run this MonoBehaviour in Edit mode.
[ExecuteInEditMode]Requirements: UnityEngine; MonoBehaviour-derived class.
Prefer ExecuteAlways for code that explicitly handles Prefab Mode. Keep editor-only APIs separate from player code.
ExecuteAlways
Section titled “ExecuteAlways”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.
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.
SelectionBase
Section titled “SelectionBase”Scene-view clicks on children select this GameObject
[SelectionBase]Requirements: UnityEngine; class attached to a GameObject.
Handy for complex hierarchies like props with many sub-meshes.
HelpURL
Section titled “HelpURL”Link the component Inspector’s help icon to a URL.
[HelpURL("https://example.com/component-help")]Requirements: UnityEngine; class; documentation URL string.
DefaultExecutionOrder
Section titled “DefaultExecutionOrder”Control script execution order.
[DefaultExecutionOrder(-100)]Requirements: UnityEngine; MonoBehaviour-derived class; constant integer order.
AssemblyIsEditorAssembly
Section titled “AssemblyIsEditorAssembly”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.
Do not treat this marker alone as a general guarantee about player-build inclusion; editor assembly and compilation settings still matter.
MovedFrom
Section titled “MovedFrom”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.
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.