Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Is there a good rebinding tutorial for new input system?

Discussion in 'Input System' started by BitBenderGames, Dec 19, 2020.

  1. BitBenderGames

    BitBenderGames

    Joined:
    Aug 9, 2015
    Posts:
    71
    Hello,

    I would like to create an ingame rebind menu where I can rebind an action - let's say "jump" - to either a new keyboard key, or a new gamepad button. The rebind menu should overwrite the existing keyboard or gamepad binding automatically depending on whether the user pressed on the keyboard or gamepad for the rebind.
    Or put in another way, I would like for the user to be able to say "rebind jump", then either tap a new key on the keyboard or on the gamepad and have that overwrite the existing binding for that device. I would like to, at all times, display in the ui something like

    Jump: [Keyboard(space)] - [Gamepad(A)]

    Maybe it's just a display issue on my part, but I'm currently trying to do the above using InputAction.PerformInteractiveRebinding() and displaying the bindings via
    InputAction.bindings.Where(item => item.path.Contains("Keyboard")).FirstOrDefault().ToDisplayString()
    and
    InputAction.bindings.Where(item => item.path.Contains("Gamepad")).FirstOrDefault().ToDisplayString()

    The result in this case is that both the keyboard as well as the gamepad binding display both show the same keyboard key if I press a key on the keyboard for example.

    Not sure what's wrong here. This post got way too specific unfortunately. I would really also appreciate a tutorial or reference manual for the new input system that is on par as the rest of the unity docs. There are so many blanks spots in the current InputSystem manual :-/

    Thanks and cheers,

    Jürgen
     
  2. Holonet

    Holonet

    Joined:
    Aug 14, 2017
    Posts:
    84
    I haven't done much with this myself yet, but in the package manager, you can expand the "Samples," and there are lots of handy sample scenes to demonstrate some functionalities, and one of them is Rebinding UI--which is basically a template for an options screen where you do just this.
     
    Ranger-Ori and Macak87 like this.
  3. quickytools

    quickytools

    Joined:
    Aug 26, 2019
    Posts:
    19
    Runtime rebinding is covered in