SerializedProperty for Enum with EnumPopup

Hy folks, I can’t manage to use EnumPopup with a SerializedProperty
here is the code:

[UnityEditor.CustomEditor(typeof(MyClass))]
public class MyClassCustomEditor : Editor {
	SerializedProperty mySerProp;
	void OnEnable () {
		mySerProp = serializedObject.FindProperty("mySerProp");
	}
	override public void OnInspectorGUI () {
		serializedObject.Update();

    // here is the problem, the example in the docs is only javascript...
    // I get 2 errors:
    // The best overloaded method match for `UnityEditor.EditorGUILayout.EnumPopup(string, System.Enum, params UnityEngine.GUILayoutOption[])' has some invalid arguments
    // and:
    // Argument `#2' cannot convert `UnityEditor.SerializedProperty' expression to type `System.Enum'
    // I've tried casting but without results..

		mySerProp = EditorGUILayout.EnumPopup("My Enum:", mySerProp);
		serializedObject.ApplyModifiedProperties();
	}
}

Hi guys, I know it’s quite late but how about this:

  EditorGUILayout.PropertyField( mySerProp );

It worked fine for me. You get a proper enum drop down from it too.

after really long long time… here is what worked for me:

mySerProp.enumValueIndex = (int)(MyEnumType)EditorGUILayout.EnumPopup("My Enum:", (MyEnumType)Enum.GetValues(typeof(MyEnumType)).GetValue(mySerProp.enumValueIndex));

Hi, here is full method maybe it will help someone in future.
First you must get your property:

SerializedProperty ourProperty = serializedObject.FindProperty(propertyPath:"nameOfPropertyInInspector");

From where get property path?
Set inspector to debug mode next put mouse coursor under name of field and press alt key - unity display name of field in code - you can use it as propertyPath.

Here is a method for set popup:

	void AddPopup (ref SerializedProperty ourSerializedProperty, string nameOfLabel, Type typeOfEnum)
	{
		Rect ourRect = EditorGUILayout.BeginHorizontal ();
		EditorGUI.BeginProperty (ourRect, GUIContent.none, ourSerializedProperty);
		EditorGUI.BeginChangeCheck ();

		int actualSelected = 1;	
		int selectionFromInspector = ourSerializedProperty.intValue;
		string[] enumNamesList = System.Enum.GetNames (typeOfEnum);
		actualSelected = EditorGUILayout.Popup (nameOfLabel, selectionFromInspector, enumNamesList);
		ourSerializedProperty.intValue = actualSelected;
	
		EditorGUI.EndProperty ();
		EditorGUILayout.EndHorizontal ();
	}

Example of how to invoke this method?

SerializedProperty lightProbes = serializedObject.FindProperty ("m_LightProbeUsage");
    AddPopup (ref lightProbes, "Light Probes", typeof(LightProbeUsage));

I know I’m posting quite late on this questions, but I’m trying to do the same thing. I have a very ugly solution that works. I’m posting it in case it is useful to someone else:

1) You have to have the enum type handy. For example we’ll say mySerProp is an enum of called MyEnumType.

2) The EnumPopup line now looks like:

mySerProp = (int)(MyEnumType)EditorGUILayout.EnumPopup(“My Enum:”, (MyEnumType)mySerProp);

If someone else has a more elegant answer to this, I would be very interested in seeing it.

The Enum popup just returns an int (which should be the index or an array or List or whatever) then you can manually update the value using that index.

Since I’ve spent many hours googling to figure out how to properly work with SerializedProperties and Enums, I’m just gonna post the best solution I could come up with here, in case it helps someone! My enum is named “AbilityType”, and this is a CustomEditor for the class “AbilityHandler”:

[CustomEditor(typeof(AbilityHandler)), CanEditMultipleObjects]
public class AbilityHandlerEditor : Editor
{
    SerializedProperty abilityType;

    private void OnEnable()
    {
        abilityType = serializedObject.FindProperty("abilityType");
    }
    
    public override void OnInspectorGUI()
    {
        // Initialize \\
        serializedObject.Update();

        // Custom Editor \\
        abilityType.enumValueIndex = (int)(AbilityType)EditorGUILayout.EnumPopup(
            (AbilityType)abilityType.enumValueIndex);

        // Finalize \\
        serializedObject.ApplyModifiedProperties();
    }
}

My class, “AbilityHandler”, starts off like this:

public class AbilityHandler : MonoBehaviour
{
    [SerializeField] AbilityType abilityType;

Hope it helps someone!