Unity-Technologies/UnityCsReference · error · ArgumentException

Command {id} does not exist

Error message

Command {id} does not exist

What it means

ArgumentException thrown by CommandService.ExecuteCommand (private) when Exists(id) is false. ExecuteCommand is invoked to run a command by id with a CommandHint and args; an unregistered id cannot resolve to a handler. Unlike GetCommandLabel, this is on the execution path (menu/shortcut invocation).

Source

Thrown at Editor/Mono/Commands/CommandService.cs:191

                {
                    if (commands.Exists(c => c.id == attr.id))
                    {
                        Debug.LogWarning($"There is already a command with the ID {attr.id}. " +
                            "Commands need to have a unique ID, i.e. \"Unity/Category/Command_42\".");
                        continue;
                    }

                    commands.Add(new Command { id = attr.id, label = attr.label ?? attr.id, hint = attr.hint, handler = callback, managed = true });
                }
            }

            return commands;
        }

        private static object ExecuteCommand(string id, CommandHint hint, object[] args)
        {
            if (!Exists(id))
                throw new ArgumentException($"Command {id} does not exist", nameof(id));

            var command = s_Commands[id];

            if ((command.hint & hint) == 0)
                throw new ArgumentException($"Command ({id}, {command.hint}) does not match the hinting {hint}", nameof(id));

            var context = new CommandExecuteContext { hint = hint, args = args, result = null };
            command.handler(context);
            return context.result;
        }
    }
}

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Guard execution with Exists(id) and skip/no-op if missing.
  2. Refresh or rebuild the menu/shortcut binding table after package/version changes.
  3. Ensure command-execution dispatch only runs after command initialization.

Example fix

// before
CommandService.Execute(id, hint, args);

// after
if (CommandService.Exists(id))
    CommandService.Execute(id, hint, args);
Defensive patterns

Strategy: validation

Validate before calling

if (!CommandService.Exists(id)) return;
CommandService.Execute(id, hint, args);

Try / catch

try { CommandService.Execute(id, hint, args); }
catch (ArgumentException ex) { /* unknown command; log and skip */ }

Prevention

When it happens

Trigger: Dispatching execution for a command id that is not registered — e.g. a menu item or key binding referencing a removed/renamed command, or invoking before attributes are scanned.

Common situations: Stale key bindings or menu layouts referencing commands removed in a newer Unity/package version; invoking a command whose owning package is disabled; timing issues where ExecuteCommand runs before OnCodeLoaded populated s_Commands.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/262e859b84aa93fb. Report an issue: GitHub.