Skip to content

Method & Editor Attributes

Context menus, editor initialization and runtime startup.

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.

Add a right-click menu to invoke this method in the Inspector.

[ContextMenu("Title")]

Requirements: UnityEngine; non-static instance method.

Primary documentation

Add a top-bar menu item for this static method.

[MenuItem("MyMenu/Action")]

Requirements: UnityEditor; static method in editor-only code.

Primary documentation

Editor: run this static method when the Editor loads.

[InitializeOnLoadMethod]

Requirements: UnityEditor; static method in editor-only code.

Primary documentation

Avoid heavy work; initialize caches or register callbacks here.

Run a static method during player startup. The parameterless attribute defaults to AfterSceneLoad; use an explicit load type for another phase.

[RuntimeInitializeOnLoadMethod]
// Alternative: explicitly run before scene loading.
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]

Requirements: UnityEngine; static method.

Primary documentation

Apply one of these alternatives to a method, rather than stacking both attributes.