Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

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

    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