+2 votes

So I've been fiddling with this, but I just cannot figure it out.
I want to do the typical options menu for changing controls: select an action from the list (for example 'JUMP'), a 'please press the key' pop-up appears (or not, doesn't matter) and the next key you press gets saved as the input for that action. Could someone provide me with a snippet of example code or just explain thoroughly how to do this (as in just catching the input event part)?

Also, I'd like to save this configuration to a file and be able to load it later on. Again, I'm not quite sure what to save here, especially that I'd like this to also support gamepads.

in Engine by (37 points)

2 Answers

+1 vote
Best answer

Godot's inputs usually use the input map. there are other ways to use inputs but the input map is the best. here is a tutorial on the input map: https://www.youtube.com/watch?v=OOnm32Uad0g

by (53 points)
selected by

Yes, my point was how to change the input map in-code, as in read the raw InputEvent and set it as the event which triggers InputMap action.

I kinda figured it out, though I do have some other related issues I'm working on. Might post a tutorial on the forum when I'm done.

0 votes

For anyone else, this is done using the InputMap class.
Here's an example in C# (you can do the same in GDScript):

// create the "jump" action:
InputMap.AddAction("jump");

// map the 'A' key to the "jump" action:
var e = new InputEventKey();
e.Set("scancode", KeyList.A);
InputMap.ActionAddEvent("jump", e);

by (14 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.