{"record":{"id":"80da9a5f915d85c4","repo":"Unity-Technologies/UnityCsReference","slug":"command-id-command-hint-does-not-match-the","errorCode":null,"errorMessage":"Command ({id}, {command.hint}) does not match the hinting {hint}","messagePattern":"Command \\((.+?), (.+?)\\) does not match the hinting (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Commands/CommandService.cs","lineNumber":196,"sourceCode":"                        continue;\n                    }\n\n                    commands.Add(new Command { id = attr.id, label = attr.label ?? attr.id, hint = attr.hint, handler = callback, managed = true });\n                }\n            }\n\n            return commands;\n        }\n\n        private static object ExecuteCommand(string id, CommandHint hint, object[] args)\n        {\n            if (!Exists(id))\n                throw new ArgumentException($\"Command {id} does not exist\", nameof(id));\n\n            var command = s_Commands[id];\n\n            if ((command.hint & hint) == 0)\n                throw new ArgumentException($\"Command ({id}, {command.hint}) does not match the hinting {hint}\", nameof(id));\n\n            var context = new CommandExecuteContext { hint = hint, args = args, result = null };\n            command.handler(context);\n            return context.result;\n        }\n    }\n}\n","sourceCodeStart":178,"sourceCodeEnd":204,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Commands/CommandService.cs#L178-L204","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Register the command with CommandHint.Any or with all the hints it should support (bitwise OR).","Check the command's hint against the intended context before executing.","Use distinct command ids per context if behavior must differ."],"exampleFix":"// before\nCommandService.RegisterCommand(id, handler, CommandHint.Menu);\n...\nCommandService.Execute(id, CommandHint.Validate, args);\n\n// after\nCommandService.RegisterCommand(id, handler, CommandHint.Menu | CommandHint.Validate);\n...\nCommandService.Execute(id, CommandHint.Validate, args);","handlingStrategy":"validation","validationCode":"// Register with all hints it should support:\nCommandService.RegisterCommand(id, handler, CommandHint.Menu | CommandHint.Validate);\n// Before executing in a context, confirm the hint intersects.","typeGuard":null,"tryCatchPattern":"try { CommandService.Execute(id, hint, args); }\ncatch (ArgumentException) { /* command not valid for this hint; skip */ }","preventionTips":["Register commands with CommandHint.Any or the union of valid contexts.","Check hint intersection before executing.","Use distinct ids per context when behavior differs."],"tags":["unity-editor","commands","argument-validation","flags","dispatch"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}