Hi

I have a custom editor script that needs to have support to change keys for specific things. But my problem is that I don’t know how. I get that you are supposed to use EnumPopup but I can’t understand in what way I should use it since no one actually says how you are going to use it.

So this is my code that I tested with.

script.movementSettings.runKey = EditorGUILayout.EnumPopup("Run Key", script.movementSettings.runKey);

Now this code doesn’t work. I get a error asking if I am missing a cast. If I add a cast in the end like “as KeyCode;” I just get another error. So how am I supposed to do this?

Any help is greatly appreciated!

Thanks!

dont use ‘as’, do it like (YourEnumType)EditorGUILayout.EnumPopup(x,x,x);

Like ValooFx said you have to use a “normal” cast. The as cast only works with reference types. An enum is a value type.

script.movementSettings.runKey = (KeyCode)EditorGUILayout.EnumPopup("Run Key", script.movementSettings.runKey);