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.
ContextMenu
Section titled “ContextMenu”Add a right-click menu to invoke this method in the Inspector.
[ContextMenu("Title")]Requirements: UnityEngine; non-static instance method.
MenuItem
Section titled “MenuItem”Add a top-bar menu item for this static method.
[MenuItem("MyMenu/Action")]Requirements: UnityEditor; static method in editor-only code.
InitializeOnLoadMethod
Section titled “InitializeOnLoadMethod”Editor: run this static method when the Editor loads.
[InitializeOnLoadMethod]Requirements: UnityEditor; static method in editor-only code.
Avoid heavy work; initialize caches or register callbacks here.
RuntimeInitializeOnLoadMethod
Section titled “RuntimeInitializeOnLoadMethod”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.
Apply one of these alternatives to a method, rather than stacking both attributes.