Changing controls at runtime

Hello,

I know unity has a built in ‘Button’ system which has built in support for dead zones and sensitivity, and that when you start up the game, you can change the controls in the configuration dialog. However, I cant seem to figure out a way to change the controls at runtime - like so in a menu screen the user can select ‘change controls’ and pick what buttons they want.

Also, I noticed it’s possible to get the mouse position, mouse buttons, and keyboard keys independantly using GetKey and GetMouseButton, but I cant see a way to get information from a gamepad except by assigning a gamepad buton to a ‘Button’ and using ‘GetButton’.

Was wondering what other people did to get around this issue, or if its planned to have some handy functions like ‘AddButton(string, ButtonData), RemoveButton(string), GetButton(string, ButtonInfo)’ or something.

Thanks for reading

At this moment, unity does not expose the InputManager in scripting. You can request that feature here though.

Besides for that, there are not any ways to change the input besides using GetKey() with a string, and that has limitations that you mentioned above.

If you are building a standalone, then the dialogue that pops up before the game opens will let the user remap the keys, but at the moment, that is the extent of it.

@The OP: You can create an in-game control configuration menu, but it basically has to be done ‘from scratch’ (that is, you have to bypass the built-in input configuration system and replace it with your own).

There’s quite a bit of info on this available in the forums (try searching for ‘input configuration’ or ‘custom input’), but feel free to ask if you have any questions about how to implement such a system.

You could probably do it like this:

  1. Make variables for each control you’ll use, e.g. string forward…
  2. Assign them to keys, e.g. forward = “w”…
  3. Then Input.GetKey() or GetKeyDown() to use them.
    That way, you won’t be accessing InputManager. But I have no idea how to do any of this.

You could use a dictionary to match a key like “Jump” with a value like “w”.
Then you can change the Value of the dictionary value to whatever the user chooses.
Using a array would probably a bit more performant but a lot less friendly to develop with.