EnumPopup - C#

I’m having trouble getting a EnumPop work in my custom editor…

Here’s my scripts:
setup.cs:

	[System.Serializable]
	public enum Race
	{
		Human,
		Necromancer,
		Orc,
		Priest
	}
	
	public Race characterRace = Race.Human;

and editor_setup.cs:

setup.characterRace = EditorGUILayout.EnumPopup ("Race:", setup.characterRace);

But this throws the error:
Cannot implicitly convert type System.Enum' to Setup.Race’

Very frustating… :stuck_out_tongue: I just can’t figure out how to do it…

1 Like

I don’t think you need to mark the enum declaration as serializable.

Well, it doesn’t work either way

The error pretty much explains what you have to do. EnumPopup returns something of type Enum, so you need to convert it to something of type Race.

Try this:

setup.characterRace = (Race) EditorGUILayout.EnumPopup ("Race:", setup.characterRace);

Or that:

setup.characterRace = (Setup.Race) EditorGUILayout.EnumPopup ("Race:", setup.characterRace);
1 Like
setup.characterRace = (setup.Race)EditorGUILayout.EnumPopup ("Race:", setup.characterRace);

Gives me the error editor_setup.setup' is a field’ but a `type’ was expected

setup.characterRace = (Race)EditorGUILayout.EnumPopup ("Race:", setup.characterRace);

Gives me the error: The type or namespace name `Race’ could not be found. Are you missing a using directive or an assembly reference?

Oh I got it now… Thanks Dantus! =)

Thx @Kovenant_1