0
\$\begingroup\$

I'm making a custom inspector for my script, and I have an option to pick a KeyCode as you can see below

key

However, now that I'm using a custom inspector, I don't know how to add a Keycode Field. I assumed it would be like the rest of the custom objects, where you would just use EditorGUILayout.ObjectField() but since KeyCode doesn't derive from UnityEngine.Object it doesn't work.

I've tried researching, but all I can find are posts on how to detect keypresses in the custom inspector. Does anyone have a solution?

\$\endgroup\$
4
  • \$\begingroup\$ Since KeyCode is an enumeration, did you try using an EnumPopup? \$\endgroup\$
    – DMGregory
    Commented Jan 15 at 22:14
  • \$\begingroup\$ That's a shout actually, Ill try that now. \$\endgroup\$
    – Pow
    Commented Jan 15 at 22:29
  • \$\begingroup\$ Yes, it works, thankyou, I just had to make sure I had the correct cast: _defaultInteractionKey = (KeyCode)EditorGUILayout.EnumPopup("Default Interaction Key", _defaultInteractionKey); \$\endgroup\$
    – Pow
    Commented Jan 15 at 22:34
  • \$\begingroup\$ If you've solved your problem, be sure to post the code that worked for you as an Answer below. \$\endgroup\$
    – DMGregory
    Commented Jan 15 at 23:01

1 Answer 1

1
\$\begingroup\$

I found you can just use a cast along with an EnumPopup, like this:

_defaultInteractionKey = (KeyCode)EditorGUILayout.EnumPopup("Default Interaction Key", _defaultInteractionKey);
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .