Unity-Technologies/UnityCsReference · error · ArgumentException

Text on buttons must be less than ${kMaxButtonTextLength} ch

Error message

Text on buttons must be less than ${kMaxButtonTextLength} characters long.

What it means

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.

Source

Thrown at Editor/Mono/EditorDialog.cs:215

            // This regular expression ensures that the key string:
            // Contains only alphanumeric characters, periods, underscores, and hyphens.
            // Is between 1 and 127 characters long.
            if (string.IsNullOrEmpty(optOutKey) || !Regex.IsMatch(optOutKey, @"^[A-Za-z0-9._-]{1,127}$"))
                throw new ArgumentException($"Key must be non-null, between 1 and 127 characters, and be a valid XML tag.", nameof(optOutKey));
        }

        private static void ThrowIfMessageIsInvalid(string messageText)
        {
            if (string.IsNullOrWhiteSpace(messageText))
                throw new ArgumentNullException(nameof(messageText), "Dialog message text cannot be null or whitespace.");
        }

        private static void ThrowIfButtonTextIsInvalid(string buttonText, string parameterName)
        {
            const int kMaxButtonTextLength = 64; // This limit is probably not necessary, but it's good to have a limit on the button text as well.
            if (buttonText != null && buttonText.Length > kMaxButtonTextLength)
                throw new ArgumentException($"Text on buttons must be less than {kMaxButtonTextLength} characters long.", parameterName);
        }

        /// <summary>
        /// Displays a simple alert dialog box with a title, an icon, a message, and a single button.
        /// </summary>
        /// <param name="messageText">The message to display in the dialog box.</param>
        /// <param name="iconType">The icon to display in the dialog box. Defaults to <see cref="DialogIconType.Warning"/>.</param>
        /// <param name="titleText">The title of the dialog box. If left null, defaults to "Unity".</param>
        /// <param name="buttonText">The text to display on the button. If left null, defaults to "OK".</param>
        /// <remarks>
        /// If <paramref name="messageText"/> is null or whitespace, an <see cref="ArgumentNullException"/> is thrown.
        /// If <paramref name="messageText"/> is longer than 512 characters, it is truncated and the full message is logged to the console in markdown format.
        /// 
        /// If <paramref name="buttonText"/> is longer than 64 characters, an <see cref="ArgumentException"/> is thrown. 
        /// </remarks>
        [RequiredByNativeCode]
        public static void DisplayAlertDialog(
            string titleText,

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Keep button labels short verbs (e.g. 'Delete', 'Cancel', 'Apply') — under 64 chars with margin.
  2. Truncate long localized strings before passing: btn = btn.Length <= 64 ? btn : btn.Substring(0, 61) + "...";
  3. Pass null to use the default OK/Cancel labels when a custom short label is not available.

Example fix

// before
EditorDialog.DisplayDialog("Title", msg, "Perform the full irreversible deletion of the selected asset now", "Cancel");
// after
EditorDialog.DisplayDialog("Title", msg, "Delete", "Cancel");
Defensive patterns

Strategy: validation

Validate before calling

const int kMaxBtn = 64;
static string TruncateButton(string s) =>
    string.IsNullOrEmpty(s) ? s : (s.Length <= kMaxBtn ? s : s.Substring(0, kMaxBtn - 3) + "...");

Type guard

static bool IsValidButtonText(string s) => s == null || s.Length <= 64;

Prevention

When it happens

Trigger: 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.

Common situations: Localized button labels that are longer in some languages; using a descriptive sentence instead of a short verb; concatenating identifiers into button text.

Related errors


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