EnumMaskField and unwanted mixed values

Hello!

I’ve been poking around Unity for fun, trying to customize the inspector of my gameplay scripts, but when it comes to enums, I can’t seem to be able to remove the “Everything”, “Nothing” options from there. Is there a way to disable the “mixed” mode and force the inspector to just allow the user to select one value? The default inspector has no problem with that so I guess it’s doable.

My enum

public enum PowerUpType
{
	NONE = 0,
	SPEEDBOOST = 1,
	FUEL = 2,
	JUMPBOOST = 3	
}

My OnInspectorGUI()

	public override void OnInspectorGUI()
	{		
		PowerUps powerup = target as PowerUps;
		powerup.PowerupType = (PowerUpType)EditorGUILayout.EnumMaskField("PowerupType",powerup.PowerupType);
	}

Unwanted result:
1359669--67600--$Capture.PNG

All I want there is the options on my enum, nothing else, not sure where those values are coming from or how to remove them. :frowning:

PS: I’m a seasoned C# programmer, but this is my first time trying to modify the inspector so please be gentle :slight_smile:

PS2: I did search google and this forum and couldn’t find anything as to how to disable mixed mode, I tried setting showMixedValue to false but to no avail.

Thanks!!

1 Like

None and Everything are autogenerated to cover the both special cases of masked values, mask values are bit combinations of each possible option in your enum. Your enum doesnt look like a real flag/mask enum.

For example this would be a valid mask/flag enum:

[Flags] // not mandatory for unity
public enum FlagTest
{
  CanBreath = 0x1,
  CanDie = 0x2,
  IsBurning = 0x4  
}

With this you can add something like this:

bool CanBreath = true;
bool CanDie = false;
bool IsBurning = true;

in one Property:

FlagTest ObjectFlags = FlagTest.CanBreath | FlagTest.IsBurning:

For your needs you should better use Unity - Scripting API: EditorGUILayout.EnumPopup

1 Like

EnumPopup worked beautifully! Thanks a LOT kind sir! Time to dig deeper and see what more I can do with it!

EnumPopup worked beautifully! Legend!