{"record":{"id":"56ded3cbf76acac2","repo":"Unity-Technologies/UnityCsReference","slug":"unsupported-enum-base-type-for-0-56ded3","errorCode":null,"errorMessage":"Unsupported enum base type for {0}","messagePattern":"Unsupported enum base type for (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Inspector/Core/AdvancedDropdown/DataSources/MultiselectDataSource.cs","lineNumber":31,"sourceCode":"        private int[] m_OptionMaskValues;\n        private string[] m_OptionNames;\n        private int[] m_SelectedOptions;\n\n        string[] m_DisplayNames;\n        int[] m_FlagValues;\n\n        public Enum enumFlags => m_EnumFlag;\n        public int mask => m_Mask;\n\n        public MultiselectDataSource(Enum enumValue)\n        {\n            m_EnumFlag = enumValue;\n            var enumType = enumFlags.GetType();\n\n            var enumData = EnumDataUtility.GetCachedEnumData(enumType);\n            if (!enumData.serializable)\n                // this is the same message used in SerializedPropertyEnumHelper.cpp\n                throw new NotSupportedException(string.Format(\"Unsupported enum base type for {0}\", enumType.Name));\n\n            m_Mask = EnumDataUtility.EnumFlagsToInt(enumData, enumFlags);\n            m_DisplayNames = enumData.displayNames;\n            m_FlagValues = enumData.flagValues;\n\n            MaskFieldGUI.GetMenuOptions(m_Mask, m_DisplayNames, m_FlagValues, out var buttonText, out var buttonTextMixed, out m_OptionNames, out m_OptionMaskValues, out m_SelectedOptions);\n        }\n\n        public MultiselectDataSource(int mask, string[] displayedOptions, int[] flagValues)\n        {\n            m_DisplayNames = displayedOptions;\n            m_FlagValues = flagValues;\n            MaskFieldGUI.GetMenuOptions(mask, displayedOptions, flagValues, out var buttonText, out var buttonTextMixed, out m_OptionNames, out m_OptionMaskValues, out m_SelectedOptions);\n        }\n\n        protected override AdvancedDropdownItem FetchData()\n        {\n            var rootGroup = new AdvancedDropdownItem(string.Empty);","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Inspector/Core/AdvancedDropdown/DataSources/MultiselectDataSource.cs#L13-L49","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n[Flags] public enum MyFlags : byte { A = 1, B = 2 } // -> NotSupportedException\n\n// after\n[Flags] public enum MyFlags { A = 1, B = 2 } // int-backed, serializable","handlingStrategy":"type-guard","validationCode":"var underlying = Enum.GetUnderlyingType(enumValue.GetType());\nif (underlying != typeof(int))\n    throw new InvalidOperationException(\"MultiselectDataSource requires an int-backed enum.\");","typeGuard":"static bool IsSerializableEnum(Type t) =>\n    t.IsEnum && Enum.GetUnderlyingType(t) == typeof(int) &&\n    EnumDataUtility.GetCachedEnumData(t).serializable;","tryCatchPattern":null,"preventionTips":["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."],"tags":["enum","flags","serialization","mask-field","dropdown"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}