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 deprecated EnumMaskFieldInternal (no-label overload) when enumValue.GetType().IsEnum is false. Because the parameter is typed 'Enum', passing null throws NullReferenceException at .GetType() before reaching this check; the ArgumentException is reached only when a non-enum value is boxed as System.Enum via an invalid cast. The whole method is [Obsolete] — use EnumFlagsField.
Source
Thrown at Editor/Mono/EditorGUI.EnumMaskField.deprecated.cs:91
public static Enum EnumMaskPopup(Rect position, GUIContent label, Enum selected, GUIStyle style)
{
int changedFlags;
bool changedToValue;
return EnumMaskPopup(position, label, selected, out changedFlags, out changedToValue, style);
}
[Obsolete("EnumMaskField has been deprecated. Use EnumFlagsField instead.")]
static Enum EnumMaskField(Rect position, GUIContent label, Enum enumValue, GUIStyle style, out int changedFlags, out bool changedToValue)
{
return DoEnumMaskField(position, label, enumValue, style, out changedFlags, out changedToValue);
}
[Obsolete("EnumMaskField has been deprecated. Use EnumFlagsField instead.")]
static Enum EnumMaskFieldInternal(Rect position, Enum enumValue, GUIStyle style)
{
Type enumType = enumValue.GetType();
if (!enumType.IsEnum)
throw new ArgumentException("Parameter enumValue must be of type System.Enum", "enumValue");
var names = Array.ConvertAll(Enum.GetNames(enumType), ObjectNames.NicifyVariableName);
int flags = MaskFieldGUIDeprecated.DoMaskField(
IndentedRect(position),
GUIUtility.GetControlID(s_MaskField, FocusType.Keyboard, position),
Convert.ToInt32(enumValue),
names, style);
return EnumDataUtility.IntToEnumFlags(enumType, flags);
}
[Obsolete("EnumMaskField has been deprecated. Use EnumFlagsField instead.")]
static Enum EnumMaskFieldInternal(Rect position, GUIContent label, Enum enumValue, GUIStyle style)
{
Type enumType = enumValue.GetType();
if (!enumType.IsEnum)
throw new ArgumentException("Parameter enumValue must be of type System.Enum", "enumValue");
var id = GUIUtility.GetControlID(s_MaskField, FocusType.Keyboard, position);View on GitHub (pinned to 225b0fbdb5)
Solutions
- Migrate to EditorGUI.EnumFlagsField / EnumFlagsFieldPopup, which carry a proper generic/Enum constraint.
- Type-check before calling: if (value == null || !value.GetType().IsEnum) reject.
- Ensure the source of the value is statically typed as a concrete enum, not object.
Example fix
// before
Enum v = (Enum)(object)someInt;
EditorGUI.EnumMaskField(rect, v);
// after
[Flags] enum MyFlags { A = 1, B = 2 }
MyFlags v = MyFlags.A | MyFlags.B;
EditorGUI.EnumFlagsField(rect, v); Defensive patterns
Strategy: type-guard
Validate before calling
if (enumValue == null || !enumValue.GetType().IsEnum)
throw new ArgumentException("enumValue must be an enum", nameof(enumValue)); Type guard
static bool IsEnumValue(Enum v) => v != null && v.GetType().IsEnum;
Prevention
- Migrate off the deprecated EnumMaskField to EnumFlagsField.
- Keep values statically typed as concrete enums at call sites.
- Type-check before invoking via reflection.
When it happens
Trigger: Calling EditorGUI.EnumMaskField (deprecated) with a value that is not actually an enum, e.g. an int or a class boxed and cast to Enum via unsafe means. Reachable through reflection-driven generic code that lost the enum constraint.
Common situations: Legacy code predating EnumFlagsField; reflection helpers that build mask fields generically and pass a boxed non-enum; ported UI code.
Related errors
- Given rpAssetType must derive from RenderPipelineAsset
- EditorApplication.OpenScene() cannot be called when in the U
- object is not a EditorBuildSettingsScene
- Check the connected players list instead
- Unknown opt out decision type
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/905a3db242768b36.
Report an issue: GitHub.