Getting Input Manager button names in-game

I found some old posts on this topic, which all said this wasn’t possible, but I was hoping something might have changed in recent years.

The idea is simple. By default, when launching a unity game, users can override they keys/buttons associated with the different “Axis” elements defined in the input manager. For example, the player could change “Jump” from one key to another. That’s a nice feature.

Now, in my game, I want to show a helpful message the first time the player needs to perform certain kinds of actions, like jumping. I want the message to show something like “Press to jump”, where is the button they mapped (or the default if they left it unchanged). However, it seems I’m unable to get the actual key or button in-game.

So, how do people handle this? I definitely want keys to be remappable. Do I need to build my own input manager just to get the name of the keys?

Thanks.

1 Like

the whole input manager system in unity is being redeveloped, but it’s not here just yet. Afaik the old posts are still relevant currently.

new version

(test version and feedback forum links in there)

Thanks for the link. I didn’t realize it was being overhauled.

Unfortunately, there isn’t any way to read or change the bindings in the Unity input manager at runtime.

By making your own input manager or using a plugin such as my input system Rewired.

If you choose to make your own, you will need to manage all button and key mappings outside the Unity input manager. The only purpose the Unity input manager serves at that point is to provide a list of axes for each joystick and the mouse so you can access them. All button and key input can be handled through UnityEngine.Input.GetKey.

1 Like

Thanks for the advice. I ended up building my own input management UI. It was actually pretty simple. I haven’t modularized it or made it general enough that I could share it with others (sorry). But I have a basic UI with buttons and labels representing the different “Actions” the player can perform (jump, move left, move right, fire, etc). Upon clicking a button, in my global GameManager’s Update method, I begin listening for keyboard or button input. When I receive it, I write that key/button value to a singleton object, and I save the configuration via PlayerPrefs so that it persists. The rest of my code that checks for inputs refers to the singleton to know which actual key/button to check for.

So overall, it was a couple of hours of work to get it all put together. I can now easily display messages like “Press ‘Space’ to Jump”, and display the appropriate key or button if the player remaps Jump to another key.

3 Likes