Unity-Technologies/UnityCsReference · error · NotImplementedException
Unknown opt out decision type
Error message
Unknown opt out decision type
What it means
Thrown by EditorDialog.SetOptOutResultForKey in the default branch of its switch on DialogOptOutDecisionType. The switch only handles ForThisSession and ForThisUser; note ForThisMachine is declared as an alias 'ForThisMachine = ForThisUser' (same integer value), so it routes to the ForThisUser branch and does NOT hit this default. The throw is therefore a defensive guard for a future-added enum member that has not been wired up. NotImplementedException signals incomplete coverage.
Source
Thrown at Editor/Mono/EditorDialog.cs:110
int sessionResult = SessionState.GetInt(prefixedKey, -1);
// We never store a result of -1 in the SessionState, so if we get -1 back, it means no result has been set.
return sessionResult == -1 ? null : (DialogResult)sessionResult;
}
private static void SetOptOutResultForKey(string key, DialogResult result, DialogOptOutDecisionType decisionType)
{
string prefixedKey = PrefixedKey(key);
switch (decisionType)
{
case DialogOptOutDecisionType.ForThisSession:
SessionState.SetInt(prefixedKey, (int)result);
break;
case DialogOptOutDecisionType.ForThisUser:
EditorPrefs.SetInt(prefixedKey, (int)result);
break;
default:
throw new NotImplementedException("Unknown opt out decision type");
}
}
private static string GetOptOutCheckboxLabel(DialogOptOutDecisionType optOutDecisionType)
{
switch (optOutDecisionType)
{
case DialogOptOutDecisionType.ForThisSession:
return L10n.Tr("Don't ask again for this session");
case DialogOptOutDecisionType.ForThisUser:
return L10n.Tr("Don't ask again on this computer");
default:
throw new NotImplementedException("Unknown opt out decision type");
}
}
private static string AdjustTitleText(string titleText)
{View on GitHub (pinned to 225b0fbdb5)
Solutions
- Validate the enum value is defined before calling: if (!Enum.IsDefined(typeof(DialogOptOutDecisionType), decisionType)) reject it.
- If you are extending the enum, also add the case here and in GetOptOutCheckboxLabel.
- For callers, stick to the named constants (ForThisSession / ForThisUser / ForThisMachine) and never cast raw ints.
Defensive patterns
Strategy: validation
Validate before calling
if (!Enum.IsDefined(typeof(DialogOptOutDecisionType), decisionType))
throw new ArgumentOutOfRangeException(nameof(decisionType)); Type guard
static bool IsKnownDecision(DialogOptOutDecisionType d) =>
d == DialogOptOutDecisionType.ForThisSession || d == DialogOptOutDecisionType.ForThisUser; Prevention
- Use only named DialogOptOutDecisionType constants; never cast raw ints.
- Validate enums reconstructed from serialized data with Enum.IsDefined.
- When adding a new enum member, update every switch over it.
When it happens
Trigger: Passing a DialogOptOutDecisionType value that is neither ForThisSession nor ForThisUser (nor the ForThisMachine alias) — only achievable today by an invalid cast from an out-of-range integer, e.g. (DialogOptOutDecisionType)42. Currently unreachable through normal API use.
Common situations: Reflection or serialization that reconstructs the enum from an arbitrary int; a future Unity version adding a new decision type before updating this switch; misuse via unsafe enum casting.
Related errors
- Unknown dialog icon type
- Key must be non-null, between 1 and 127 characters, and be a
- Dialog message text cannot be null or whitespace.
- Text on buttons must be less than ${kMaxButtonTextLength} ch
- Parameter enumValue must be of type System.Enum
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/2c598ceff53f8ca5.
Report an issue: GitHub.