Custom input system

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JulioYagami

I am currently working on the game settings and need a way for the player to define his own inputs. For example, I have an action with the “E” key attached to. Is there a way to change this action key (by GDScript, I imagine)?

1 Like
:bust_in_silhouette: Reply From: SIsilicon

The InputMap Singleton sounds like just what you need. You would have a GUI setup that shows all actions the player can edit. When you press a button, you set the action variable of the below code segment to the input event. You would put said code in a GUI node maybe.

var action_edited # a String holding the action you want to edit (ui_up, ui_down, etc..)

...

func _input(event):
     if action_edited and event is InputEventKey and event.pressed:
         InputMap.erase_action(action_edited)
         InputMap.add_action(action_edited)
         InputMap.action_add_event(action_edited, event)

         action_edited = null
1 Like