Define and name Unity CLI commands
Define Unity CLI commands with the CliCommand attribute, and choose consistent names for groups, commands, arguments, and tags.
Read time 4 minutesLast updated 5 days ago
To define a command, add the attribute to a static method and pass the group the command belongs to:
[CliCommand][CliCommand( group: "animation.animator", // Required description: "Creates an Animator Controller asset.", Tags = new[] { "destructive" })] // Optional labels onlystatic CommandResult CreateController(...) // Command name: create_controller
The parameter is required. You can pass any group string. If no with that name exists yet, passing it creates the group.
groupgroupTo register a command in code instead of with the attribute, call . It takes the same parameter, and you must pass the name explicitly.
CommandRegistry.RegisterCommandgroupHow the command name is derived
The parameter is optional. If you omit it, the command name is the method name converted to snake_case:
nameRule | Method name | Command name |
|---|---|---|
Split the name at each capital letter and join the words with | | |
| Treat an acronym as one word. | | |
| Keep digits with the word before them. | | |
Override the command name
To set the command name yourself, pass in the attribute. The value you pass replaces the derived name. Use this to rename a method without breaking the command name that users and scripts rely on:
Name[CliCommand(group: "animation.animator", Name = "create_controller")]static CommandResult MakeAnimatorController(...)
Name commands
Write group and command names in lowercase snake_case. The Pipeline package follows the conventions in this section for its own commands. They're recommendations, not requirements: you can use your own groups, names, and verbs.
If the last segment of the group already names the object the command acts on, use only a verb as the command name. For example, the command that creates a clip in the group is :
animation.clipcreateunity command animation.clip createunity command animation.timeline create
If the command acts on a different object, add the object after the verb. For example, the command that creates a controller in the group is .
animation.animatorcreate_controllerThe following table shows examples of both patterns:
Group | Command name | Pattern |
|---|---|---|
| | Verb only. The group already names the object. |
| | Verb only. The group already names the object. |
| | Verb and object. |
| | Verb and object. |
Choose a verb
Reuse the verbs the Pipeline package already uses where they fit. Some verbs have a specific meaning:
Verb | Use it to |
|---|---|
| Return the state of one object. |
| Enumerate a known set of objects. |
| Query objects that match a condition. |
| Make a new persistent artifact, such as an asset. |
| Attach something to an existing parent object. |
The other common verbs mean what they say: , , , , , , , , and .
setdeleteremoverenamemovecopyruncancelstatusYou can also use domain verbs, such as , , , , , , , , , or . If none of these verbs fit, use any other verb that describes the operation.
bakeapplyimportinstantiaterecompilesavesearchstartstopswitchOrganize commands into subgroups
If an object has many commands, give it its own subgroup, such as , and use plain verbs for the command names. If an object has only a few commands, include the object in the command name instead, such as . The last segment of a subgroup is usually a noun. How you split a group is your decision as the command author.
animation.animator.controllercreate_controllerThe Pipeline package always uses subgroups for settings, with one subgroup per domain. For example, to read or write Player settings, use the subgroup:
settings.playerunity command settings.player getunity command settings.player set
Name arguments
Follow these rules when you name command arguments:
- Use lowercase snake_case, such as ,
game_object, ormodule_name. Don't use hyphens.max_depth - Name an argument that takes one asset or file path as . Name an argument that takes several paths as
path.paths - Name Boolean flags as positive assertions. For example, use rather than
enable.enabled
Arguments can only use types that the Unity CLI can convert from command-line parameters. The command system validates parameter types when it registers a command.
Add tags
Tags describe what a command is like, such as , , , or . A command can have no tags or any number of tags. Don't use tags to say where a command lives, because that's the purpose of the group.
destructiveasyncruntimedry_runAs groups and tags are separate, you can combine them to filter commands. For example, the following options list the commands in the group that aren't tagged :
lightingdestructive--group lighting --exclude-tag destructive