Unity-Technologies/UnityCsReference · error · NotSupportedException
Unsupported enum base type for {0}
Error message
Unsupported enum base type for {0} What it means
MultiselectDataSource checks EnumDataUtility.GetCachedEnumData(...).serializable before building flag/mask data, and throws NotSupportedException when false. The serialization layer only supports enums whose underlying type is int; enums backed by byte, sbyte, short, ushort, uint, long, or ulong are considered non-serializable and cannot be used with the multiselect/mask dropdown.
Source
Thrown at Editor/Mono/Inspector/Core/AdvancedDropdown/DataSources/MultiselectDataSource.cs:31
private int[] m_OptionMaskValues;
private string[] m_OptionNames;
private int[] m_SelectedOptions;
string[] m_DisplayNames;
int[] m_FlagValues;
public Enum enumFlags => m_EnumFlag;
public int mask => m_Mask;
public MultiselectDataSource(Enum enumValue)
{
m_EnumFlag = enumValue;
var enumType = enumFlags.GetType();
var enumData = EnumDataUtility.GetCachedEnumData(enumType);
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));
m_Mask = EnumDataUtility.EnumFlagsToInt(enumData, enumFlags);
m_DisplayNames = enumData.displayNames;
m_FlagValues = enumData.flagValues;
MaskFieldGUI.GetMenuOptions(m_Mask, m_DisplayNames, m_FlagValues, out var buttonText, out var buttonTextMixed, out m_OptionNames, out m_OptionMaskValues, out m_SelectedOptions);
}
public MultiselectDataSource(int mask, string[] displayedOptions, int[] flagValues)
{
m_DisplayNames = displayedOptions;
m_FlagValues = flagValues;
MaskFieldGUI.GetMenuOptions(mask, displayedOptions, flagValues, out var buttonText, out var buttonTextMixed, out m_OptionNames, out m_OptionMaskValues, out m_SelectedOptions);
}
protected override AdvancedDropdownItem FetchData()
{
var rootGroup = new AdvancedDropdownItem(string.Empty);View on GitHub (pinned to 225b0fbdb5)
Solutions
- Change the enum's underlying type to int (remove `: byte`/`: long` etc.).
- If you cannot change the enum, map its values to an int-backed enum before passing to MultiselectDataSource.
- Use the int-mask constructor overload MultiselectDataSource(int mask, string[], int[]) instead of the Enum-based one.
- Verify with Enum.GetUnderlyingType(typeof(MyEnum)) == typeof(int) before constructing.
Example fix
// before
[Flags] public enum MyFlags : byte { A = 1, B = 2 } // -> NotSupportedException
// after
[Flags] public enum MyFlags { A = 1, B = 2 } // int-backed, serializable Defensive patterns
Strategy: type-guard
Validate before calling
var underlying = Enum.GetUnderlyingType(enumValue.GetType());
if (underlying != typeof(int))
throw new InvalidOperationException("MultiselectDataSource requires an int-backed enum."); Type guard
static bool IsSerializableEnum(Type t) =>
t.IsEnum && Enum.GetUnderlyingType(t) == typeof(int) &&
EnumDataUtility.GetCachedEnumData(t).serializable; Prevention
- Declare flags enums without an explicit non-int base type.
- Prefer the int-mask MultiselectDataSource overload when the source enum is non-int-backed.
- Centralize enum-to-mask conversion behind a helper that checks the underlying type.
When it happens
Trigger: Constructing MultiselectDataSource with an Enum whose underlying type is not int (e.g. `enum Flags : byte`, `enum Flags : long`). The shared comment notes this matches SerializedPropertyEnumHelper.cpp behavior, so the same enums fail in serialized property enum fields.
Common situations: Using a [Flags] enum declared with a non-int base type for a mask field. Interop/data-compact enums that specify `: byte` for size, then fed into an editor mask dropdown. Third-party enums with custom base types.
Related errors
- Parameter enumValue must be of type System.Enum
- Unsupported enum base type for {0}
- Parameter asset is null
- Cannot serialize json value of unknown type
- Command ({id}, {command.hint}) does not match the hinting {h
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/56ded3cbf76acac2.
Report an issue: GitHub.