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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Can you do custom keybinds with the new input system?

Discussion in 'Input System' started by noamro, Aug 18, 2020.

  1. noamro

    noamro

    Joined:
    Dec 28, 2017
    Posts:
    16
    I'm wondering if it's possible to create a custom keybinding system using the new input system.
    has anyone tried it?
     
  2. smasson99

    smasson99

    Joined:
    Oct 1, 2017
    Posts:
    10
    Hi! It is indeed possible to rebind your inputs with the Input System. You will need to use the "PerformInteractiveRebinding" function.

    Here's an example from my code :

    actionToRebind.Disable();
    rebindingOperation?.Dispose();
    rebindingOperation = actionToRebind
    .PerformInteractiveRebinding()
    .WithTargetBinding(onKeyBinderClicked.KeyBindingProfile.GetBindingIndex())
    .WithControlsExcluding("<Mouse>/position")
    .WithControlsExcluding("<Mouse>/delta")
    .WithExpectedControlType("Button")
    .OnMatchWaitForAnother(0.1f)
    .OnCancel(OnRebindCancelled)
    .OnComplete(OnRebindCompleted)
    .Start();
     
  3. noamro

    noamro

    Joined:
    Dec 28, 2017
    Posts:
    16
    For some reason I can't call this method when clicking on a button
    it's not showing on the list

    upload_2020-8-19_13-6-18.png

    void RemapButtonClicked(InputAction actionToRebind)
    {
    var rebindOperation = actionToRebind.PerformInteractiveRebinding()
    // To avoid accidental input from mouse motion
    .WithControlsExcluding("Mouse")
    .OnMatchWaitForAnother(0.1f)
    .Start();
    }
     
  4. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    The signature doesn't match.

    Would recommend taking a look at the "Rebinding UI" sample coming with the input system package (can be installed from the package manager window with the input system package selected; there's a list of samples there). May give you a headstart.
     
  5. noamro

    noamro

    Joined:
    Dec 28, 2017
    Posts:
    16
    I tried looking at the "Tanks" sample, and it still didn't worked out.
    I'll try the "Rebinding UI" one.
    Can you explain what you mean by "signature doesn't match"?

    Edit:
    I copied the code from rebinding ui and tried it in my game.
    it seems to work, no errors + the icons change when I try to rebind, but the rebind itself doesn't work.
    the same old key still does the same and the new one does nothing, for some reason I can't "save" the changes
     
    Last edited: Aug 19, 2020