{"record":{"id":"80b517f2c7cba73e","repo":"Unity-Technologies/UnityCsReference","slug":"parameter-enumvalue-must-be-of-type-system-enum-80b517","errorCode":null,"errorMessage":"Parameter enumValue must be of type System.Enum","messagePattern":"Parameter enumValue must be of type System\\.Enum","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/EditorGUI.cs","lineNumber":4663,"sourceCode":"        {\n            return EnumFlagsField(position, label, enumValue, false, style);\n        }\n\n        public static Enum EnumFlagsField(Rect position, GUIContent label, Enum enumValue, [DefaultValue(\"false\")] bool includeObsolete, [DefaultValue(\"null\")] GUIStyle style = null)\n        {\n            return EnumFlagsField(position, label, enumValue, includeObsolete, out _, out _, style ?? EditorStyles.popup);\n        }\n\n        // Internal version that also gives you back which flags were changed and what they were changed to.\n        internal static Enum EnumFlagsField(Rect position, GUIContent label, Enum enumValue, bool includeObsolete, out int changedFlags, out bool changedToValue, GUIStyle style)\n        {\n            return EnumFlagsField(position, label, enumValue, enumValue.GetType(), includeObsolete, out changedFlags, out changedToValue, style);\n        }\n\n        internal static Enum EnumFlagsField(Rect position, GUIContent label, Enum enumValue, Type enumType, bool includeObsolete, out int changedFlags, out bool changedToValue, GUIStyle style)\n        {\n            if (!enumType.IsEnum)\n                throw new ArgumentException(\"Parameter enumValue must be of type System.Enum\", nameof(enumValue));\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            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        }","sourceCodeStart":4645,"sourceCodeEnd":4681,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/EditorGUI.cs#L4645-L4681","documentation":"Thrown by the type-explicit overload of EnumFlagsField when enumType.IsEnum is false. Like the popup sibling, the Enum-typed overload derives the type from the value, so this guard realistically fires for callers passing an explicit non-enum Type. The message names the 'enumValue' parameter for legacy parity.","triggerScenarios":"Calling EnumFlagsField with a Type argument that is not an enum (typeof(long) used as a bitfield, a class type, or a null-coalesced default). The int-flag and explicit-Type overloads are the realistic paths.","commonSituations":"Refactored inspector code that previously used EnumMaskField with an int and migrated the Type argument incorrectly; generic bitfield helpers that accept any Type.","solutions":["Pass the enum value directly so the framework derives the type, instead of supplying a Type separately.","Pre-validate enumType.IsEnum and abort the field render with a HelpBox if it fails.","Use an Enum-constrained generic wrapper around EnumFlagsField."],"exampleFix":"// before\nEnumFlagsField(rect, label, 0, typeof(int), false, style);\n\n// after\nEnumFlagsField(rect, label, (MyEnum)0, false, style);","handlingStrategy":"type-guard","validationCode":"if (enumType == null || !enumType.IsEnum) { Debug.LogError(\"EnumFlagsField requires an enum type\"); return enumValue; }","typeGuard":"static bool IsEnumType(Type t) => t != null && t.IsEnum;","tryCatchPattern":null,"preventionTips":["Use the Enum-typed EnumFlagsField overload to let the framework derive the Type.","Constrain generic helpers with 'where T : struct, Enum'.","Unit-test enum fields with a representative enum before shipping the inspector."],"tags":["csharp","unity-editor","enum","gui","flags-field"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}