How to display the key codes of certain buttons?

Hello.

I currently have the standard FPS Controller and I’m using the default Input Manager in my game.

My FPS Controller’s camera has a script attached to it that has a raycast specifically for detecting interactable objects. If the raycast hits an object that you can interact with it, it writes a text saying something like “click here to interact”.

What I want, however, is to display the key that is assigned for interacting. Right now I have a custom button set in the Input manager that is named “Interact” and its default key is F.
I want the script to display the actual key, even if it would be remapped to something else, like E or R or whatever.

I have tried googling this, but the only closest thing I seem to find is detecting which key was pressed, which is not what I want. I only want to display a key that the person needs to press in order to activate the object.

Is that somehow possible without writing a custom Input Manager?

Thank you.

Sadly all that info in Unity’s Input Manager is kept in its C++ side and is inaccessible. you would have to write your own Input Manager storing your keybind. and then instead of using UnityEngine.Input you call your InputManager (which behind the scenes calls UnityEngine.Input).

I looked into this when I was looking for how to rebind inputs at runtime, and to mask input at certain times (i.e. disable specific inputs during cutscenes or when typing in a chat box). Suffice to say it ended up where I had to write my own Manager. The real nightmare was then hunting down all scripts (especially third-party) using Input class and have them use the InputManager instead

2 Likes

Maybe in the new input system can (once it arrives…)
https://feedback.unity3d.com/suggestions/scripting-expose-input-manager-