MenuCommand Manual     Reference     Scripting  
Scripting > Editor Classes > MenuCommand
MenuCommand Class

Used to extract the context for a MenuItem. MenuCommand objects are passed to custom menu item functions defined using the MenuItem attribute.

Note: This is an editor class. To use it you have to place your script in Assets/Editor inside your project folder. Editor classes are in the UnityEditor namespace so for C# scripts you need to add "using UnityEditor;" at the beginning of the script.

// Add context menu named "Do Something" to context menu
@MenuItem ("CONTEXT/Rigidbody/Do Something")
static function DoSomething (command : MenuCommand) {
var body : Rigidbody = command.context;
body.mass = 5;

See Also: MenuItem


Context is the object that is the target of a menu command.


An integer for passing custom information to a menu item.


Creates a new MenuCommand object.