Unity-Technologies/UnityCsReference · error · ArgumentException
Parameter enumValue must be of type System.Enum
Error message
Parameter enumValue must be of type System.Enum
What it means
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.
Source
Thrown at Editor/Mono/EditorGUI.cs:4663
{
return EnumFlagsField(position, label, enumValue, false, style);
}
public static Enum EnumFlagsField(Rect position, GUIContent label, Enum enumValue, [DefaultValue("false")] bool includeObsolete, [DefaultValue("null")] GUIStyle style = null)
{
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);
}View on GitHub (pinned to 225b0fbdb5)
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.
Example fix
// before EnumFlagsField(rect, label, 0, typeof(int), false, style); // after EnumFlagsField(rect, label, (MyEnum)0, false, style);
Defensive patterns
Strategy: type-guard
Validate before calling
if (enumType == null || !enumType.IsEnum) { Debug.LogError("EnumFlagsField requires an enum type"); return enumValue; } Type guard
static bool IsEnumType(Type t) => t != null && t.IsEnum;
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Refactored inspector code that previously used EnumMaskField with an int and migrated the Type argument incorrectly; generic bitfield helpers that accept any Type.
Related errors
- Specified enumType must be System.Enum
- Parameter selected must be of type System.Enum
- Unsupported enum base type for {0}
- The DialogOptOut type named {0} has not been implemented.
- Specify exactly one edge
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/80b517f2c7cba73e.
Report an issue: GitHub.