Unity-Technologies/UnityCsReference · error · ArgumentException

Command ({id}, {command.hint}) does not match the hinting {h

Error message

Command ({id}, {command.hint}) does not match the hinting {hint}

What it means

ArgumentException thrown by CommandService.ExecuteCommand when the resolved command's hint bitmask does not intersect the requested hint ((command.hint & hint) == 0). CommandHint distinguishes contexts in which a command is valid (e.g. menu vs. shortcut vs. validate); invoking a command in a context it was not registered for is rejected.

Source

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

                        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. Register the command with CommandHint.Any or with all the hints it should support (bitwise OR).
  2. Check the command's hint against the intended context before executing.
  3. Use distinct command ids per context if behavior must differ.

Example fix

// before
CommandService.RegisterCommand(id, handler, CommandHint.Menu);
...
CommandService.Execute(id, CommandHint.Validate, args);

// after
CommandService.RegisterCommand(id, handler, CommandHint.Menu | CommandHint.Validate);
...
CommandService.Execute(id, CommandHint.Validate, args);
Defensive patterns

Strategy: validation

Validate before calling

// Register with all hints it should support:
CommandService.RegisterCommand(id, handler, CommandHint.Menu | CommandHint.Validate);
// Before executing in a context, confirm the hint intersects.

Try / catch

try { CommandService.Execute(id, hint, args); }
catch (ArgumentException) { /* command not valid for this hint; skip */ }

Prevention

When it happens

Trigger: Executing a command with a CommandHint that does not match the hint it was registered with. E.g. a command registered with CommandHint.Menu invoked with a validate hint, or a shortcut-only command invoked from a menu context.

Common situations: Calling Execute with the wrong hint in custom dispatchers; reusing a command id across contexts without the right hint flags; changes to CommandHint flags across versions.

Related errors


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