Unity-Technologies/UnityCsReference · error · NotSupportedException
Unsupported enum base type for {0}
Error message
Unsupported enum base type for {0} What it means
Thrown by EnumFlagsField when the enum passes the IsEnum check but EnumDataUtility marks it as not serializable. Unity only serializes enums whose underlying integral type is one it can store; the serializable flag is false for enums backed by unsupported base types. The mask field refuses to operate because it cannot round-trip the flags to a serializable int.
Source
Thrown at Editor/Mono/EditorGUI.cs:4668
{
return EnumFlagsField(position, label, enumValue, includeObsolete, out _, out _, style ?? EditorStyles.popup);
}
// Internal version that also gives you back which flags were changed and what they were changed to.
internal static Enum EnumFlagsField(Rect position, GUIContent label, Enum enumValue, bool includeObsolete, out int changedFlags, out bool changedToValue, GUIStyle style)
{
return EnumFlagsField(position, label, enumValue, enumValue.GetType(), includeObsolete, out changedFlags, out changedToValue, style);
}
internal static Enum EnumFlagsField(Rect position, GUIContent label, Enum enumValue, Type enumType, bool includeObsolete, out int changedFlags, out bool changedToValue, GUIStyle style)
{
if (!enumType.IsEnum)
throw new ArgumentException("Parameter enumValue must be of type System.Enum", nameof(enumValue));
var enumData = EnumDataUtility.GetCachedEnumData(enumType, !includeObsolete);
if (!enumData.serializable)
// this is the same message used in SerializedPropertyEnumHelper.cpp
throw new NotSupportedException(string.Format("Unsupported enum base type for {0}", enumType.Name));
var id = GUIUtility.GetControlID(s_EnumFlagsField, FocusType.Keyboard, position);
position = PrefixLabel(position, id, label);
var flagsInt = EnumDataUtility.EnumFlagsToInt(enumData, enumValue);
BeginChangeCheck();
flagsInt = MaskFieldGUI.DoMaskField(position, id, flagsInt, enumData.displayNames, enumData.flagValues, style, out changedFlags, out changedToValue);
if (!EndChangeCheck())
return enumValue;
return EnumDataUtility.IntToEnumFlags(enumType, flagsInt);
}
internal static int EnumFlagsField(Rect position, GUIContent label, int enumValue, Type enumType, bool includeObsolete, GUIStyle style)
{
if (!enumType.IsEnum)
throw new ArgumentException("Specified enumType must be System.Enum", nameof(enumType));View on GitHub (pinned to 225b0fbdb5)
Solutions
- Change the enum's underlying type to int (the most widely supported base) and recompile.
- If you need a wide bitfield, verify the exact Unity version's supported enum base types and pick one that is serializable.
- Render the field with a custom mask int control instead of EnumFlagsField if you must keep the non-serializable base type.
Example fix
// before
public enum BigFlags : ulong { A = 1, B = 2 }
// after
public enum BigFlags : int { A = 1, B = 2 } Defensive patterns
Strategy: validation
Validate before calling
var data = EnumDataUtility.GetCachedEnumData(enumType, true);
if (!data.serializable) { Debug.LogWarning($"{enumType.Name} is not serializable; cannot render as flags"); return enumValue; } Type guard
static bool IsSerializableEnum(Type t) => t != null && t.IsEnum && EnumDataUtility.GetCachedEnumData(t, true).serializable;
Try / catch
try { EnumFlagsField(rect, label, enumValue, includeObsolete, out _, out _, style); } catch (NotSupportedException) { EditorGUI.HelpBox(rect, $"{enumType.Name} has an unsupported base type", MessageType.Warning); } Prevention
- Define project enums with an int base type unless you have confirmed broader support.
- Audit third-party enums before rendering them with EnumFlagsField.
- Centralize enum-field rendering in a helper that checks serializable status.
When it happens
Trigger: Defining an enum with an unsupported underlying type (in older Unity only int-backed enums serialize; later versions accept byte/sbyte/short/ushort/int/uint/long/ulong, but a few niche base types or unsigned long on certain platforms still fail), then rendering it with EnumFlagsField.
Common situations: A project uses an enum like 'public enum E : ulong' or a custom base, and the cached EnumData reports serializable=false. Mixed-platform builds where the underlying type behavior differs.
Related errors
- Parameter enumValue must be of type System.Enum
- Specified enumType must be System.Enum
- Parameter selected must be of type System.Enum
- Invalid JSON value: ${jsonValue}
- The DialogOptOut type named {0} has not been implemented.
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/0e6e32e4e478b16f.
Report an issue: GitHub.