Search Unity

Get name of mapped key with new input system?

Discussion in 'Input System' started by Zebbi, Jul 27, 2020.

  1. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    if I wanted to display “Press [space] to open door”, where [space] is the name of the mapped key, is this possible with the new input system? So depending on what the user has this bound to, it could say “Press E to open door” or “Press X button to open door”?
     
  2. uani

    uani

    Joined:
    Sep 6, 2013
    Posts:
    232
  3. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Thank you so much, I’ll try that!
     
  4. mikeohc

    mikeohc

    Joined:
    Jul 1, 2020
    Posts:
    215
    Is it possible to find a binding index by the active inputcontrol scheme?

    Say I have
    inputAction.bindings[0].name
    for a gamepad, and
    inputAction.bindings[1].name
    for keyboard, how would I return the correct binding without hardcoding the
    x
    index?

    For anyone stumbling upon this the answer is here:
    Link to doc
    In short,
    action.GetBindingDisplayString();
     
    Last edited: Aug 26, 2021
  5. xXFUNNYJOKEXx

    xXFUNNYJOKEXx

    Joined:
    Jul 30, 2020
    Posts:
    2
    A little late but for anyone who stumbles upon this I found a solution.

    Code (CSharp):
    1. PlayerInput playerInput;
    2.  
    3. private void Start()
    4. {
    5.         playerInput = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerInput>(); //Just my code to get the player input action map.
    6.         Debug.Log(playerInput.currentActionMap.FindAction("Jump").GetBindingDisplayString(0)); // Replace the "Jump with the name of the action you have in your action map and the GetBindingDisplayString(0) the 0 is the order in the array of keybinds set to the action, so 0 will be the first one"
    7. }