- Home /
KeyCode in custom editor
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!
Answer by Polymo · Sep 12, 2015 at 12:57 PM
dont use 'as', do it like (YourEnumType)EditorGUILayout.EnumPopup(x,x,x);
Answer by Bunny83 · Sep 12, 2015 at 01:13 PM
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);
Your answer
Follow this Question
Related Questions
Drawing a custom variable in the inspector y position bugs selection 0 Answers
Saving custom inspector references 1 Answer
Custom Editor for Interface/Child classes not displaying 2 Answers
Inspector: custom property with custom type use default editor 3 Answers
How to provide custom descriptions for EditorGUI.EnumPopup? 1 Answer