{"record":{"id":"a95a9c38b02c6539","repo":"Unity-Technologies/UnityCsReference","slug":"text-on-buttons-must-be-less-than-kmaxbuttontext","errorCode":null,"errorMessage":"Text on buttons must be less than ${kMaxButtonTextLength} characters long.","messagePattern":"Text on buttons must be less than (.+?) characters long\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/EditorDialog.cs","lineNumber":215,"sourceCode":"\n            // This regular expression ensures that the key string:\n            // Contains only alphanumeric characters, periods, underscores, and hyphens.\n            // Is between 1 and 127 characters long.\n            if (string.IsNullOrEmpty(optOutKey) || !Regex.IsMatch(optOutKey, @\"^[A-Za-z0-9._-]{1,127}$\"))\n                throw new ArgumentException($\"Key must be non-null, between 1 and 127 characters, and be a valid XML tag.\", nameof(optOutKey));\n        }\n\n        private static void ThrowIfMessageIsInvalid(string messageText)\n        {\n            if (string.IsNullOrWhiteSpace(messageText))\n                throw new ArgumentNullException(nameof(messageText), \"Dialog message text cannot be null or whitespace.\");\n        }\n\n        private static void ThrowIfButtonTextIsInvalid(string buttonText, string parameterName)\n        {\n            const int kMaxButtonTextLength = 64; // This limit is probably not necessary, but it's good to have a limit on the button text as well.\n            if (buttonText != null && buttonText.Length > kMaxButtonTextLength)\n                throw new ArgumentException($\"Text on buttons must be less than {kMaxButtonTextLength} characters long.\", parameterName);\n        }\n\n        /// <summary>\n        /// Displays a simple alert dialog box with a title, an icon, a message, and a single button.\n        /// </summary>\n        /// <param name=\"messageText\">The message to display in the dialog box.</param>\n        /// <param name=\"iconType\">The icon to display in the dialog box. Defaults to <see cref=\"DialogIconType.Warning\"/>.</param>\n        /// <param name=\"titleText\">The title of the dialog box. If left null, defaults to \"Unity\".</param>\n        /// <param name=\"buttonText\">The text to display on the button. If left null, defaults to \"OK\".</param>\n        /// <remarks>\n        /// If <paramref name=\"messageText\"/> is null or whitespace, an <see cref=\"ArgumentNullException\"/> is thrown.\n        /// If <paramref name=\"messageText\"/> is longer than 512 characters, it is truncated and the full message is logged to the console in markdown format.\n        /// \n        /// If <paramref name=\"buttonText\"/> is longer than 64 characters, an <see cref=\"ArgumentException\"/> is thrown. \n        /// </remarks>\n        [RequiredByNativeCode]\n        public static void DisplayAlertDialog(\n            string titleText,","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/EditorDialog.cs#L197-L233","documentation":"Thrown by EditorDialog.ThrowIfButtonTextIsInvalid when any button text exceeds kMaxButtonTextLength (64 characters). Note null button text is allowed (it defaults to OK/Cancel); only non-null text longer than 64 chars throws. The limit is a UI sanity cap on button labels.","triggerScenarios":"Calling an EditorDialog.DisplayDialog overload whose button text argument(s) are non-null and longer than 64 characters. Passing a full sentence or a localized string that expanded past the cap.","commonSituations":"Localized button labels that are longer in some languages; using a descriptive sentence instead of a short verb; concatenating identifiers into button text.","solutions":["Keep button labels short verbs (e.g. 'Delete', 'Cancel', 'Apply') — under 64 chars with margin.","Truncate long localized strings before passing: btn = btn.Length <= 64 ? btn : btn.Substring(0, 61) + \"...\";","Pass null to use the default OK/Cancel labels when a custom short label is not available."],"exampleFix":"// before\nEditorDialog.DisplayDialog(\"Title\", msg, \"Perform the full irreversible deletion of the selected asset now\", \"Cancel\");\n// after\nEditorDialog.DisplayDialog(\"Title\", msg, \"Delete\", \"Cancel\");","handlingStrategy":"validation","validationCode":"const int kMaxBtn = 64;\nstatic string TruncateButton(string s) =>\n    string.IsNullOrEmpty(s) ? s : (s.Length <= kMaxBtn ? s : s.Substring(0, kMaxBtn - 3) + \"...\");","typeGuard":"static bool IsValidButtonText(string s) => s == null || s.Length <= 64;","tryCatchPattern":null,"preventionTips":["Keep button labels to short verbs.","Truncate or shorten localized labels that exceed 64 chars.","Pass null to accept the default OK/Cancel when unsure."],"tags":["editor","dialog","validation","length-limit","localization"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}