{"record":{"id":"529af9b89e57aa5a","repo":"Unity-Technologies/UnityCsReference","slug":"specified-enumtype-must-be-system-enum","errorCode":null,"errorMessage":"Specified enumType must be System.Enum","messagePattern":"Specified enumType must be System\\.Enum","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/EditorGUI.cs","lineNumber":4686,"sourceCode":"                throw new NotSupportedException(string.Format(\"Unsupported enum base type for {0}\", enumType.Name));\n\n            var id = GUIUtility.GetControlID(s_EnumFlagsField, FocusType.Keyboard, position);\n            position = PrefixLabel(position, id, label);\n\n            var flagsInt = EnumDataUtility.EnumFlagsToInt(enumData, enumValue);\n\n            BeginChangeCheck();\n            flagsInt = MaskFieldGUI.DoMaskField(position, id, flagsInt, enumData.displayNames, enumData.flagValues, style, out changedFlags, out changedToValue);\n            if (!EndChangeCheck())\n                return enumValue;\n\n            return EnumDataUtility.IntToEnumFlags(enumType, flagsInt);\n        }\n\n        internal static int EnumFlagsField(Rect position, GUIContent label, int enumValue, Type enumType, bool includeObsolete, GUIStyle style)\n        {\n            if (!enumType.IsEnum)\n                throw new ArgumentException(\"Specified enumType must be System.Enum\", nameof(enumType));\n\n            var enumData = EnumDataUtility.GetCachedEnumData(enumType, !includeObsolete);\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            var id = GUIUtility.GetControlID(s_EnumFlagsField, FocusType.Keyboard, position);\n            position = PrefixLabel(position, id, label);\n\n            int changedFlags;\n            bool changedToValue;\n            return MaskFieldGUI.DoMaskField(position, id, enumValue, enumData.displayNames, enumData.flagValues, style, out changedFlags, out changedToValue, enumType.GetEnumUnderlyingType());\n        }\n\n        public static void ObjectField(Rect position, SerializedProperty property)\n        {\n            ObjectField(position, property, null, null, EditorStyles.objectField);\n        }","sourceCodeStart":4668,"sourceCodeEnd":4704,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/EditorGUI.cs#L4668-L4704","documentation":"Thrown by the int-flag overload of EnumFlagsField when enumType.IsEnum is false. Unlike 184, this overload legitimately accepts an int value plus a Type, so the guard is the primary defense: callers supply a Type, and if it is not an enum the method refuses. The message correctly names 'enumType'.","triggerScenarios":"Calling EnumFlagsField(rect, label, someInt, someType, ...) where someType is typeof(int), typeof(string), or any non-enum. This is the realistic hit because the int overload is explicitly Type-driven.","commonSituations":"Generic bitfield editor utilities that store flags as int and pass a Type from a runtime registry; migrated code where the Type argument was left as the underlying integral type.","solutions":["Guard with if (!type.IsEnum) before calling the int overload.","Switch to the Enum-typed overload so the Type is always derived from a real enum value.","Fix the registry/config to reference the actual enum type, not its underlying type."],"exampleFix":"// before\nEnumFlagsField(rect, label, flags, typeof(int), false, style);\n\n// after\nEnumFlagsField(rect, label, flags, typeof(MyFlagsEnum), false, style);","handlingStrategy":"type-guard","validationCode":"if (enumType == null || !enumType.IsEnum) { Debug.LogError($\"{enumType} is not an enum\"); return enumValue; }","typeGuard":"static bool IsEnumType(Type t) => t != null && t.IsEnum;","tryCatchPattern":null,"preventionTips":["Pass the actual enum Type (not its underlying integral type) to the int-flag EnumFlagsField.","Validate Type registry entries with IsEnum before invoking.","Prefer the Enum-typed overload where possible."],"tags":["csharp","unity-editor","enum","gui","flags-field","type-guard"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}