Search Unity

ReBind keys on action with multiple keys, on runtime

Discussion in 'Input System' started by VoidCooper, Aug 16, 2019.

  1. VoidCooper

    VoidCooper

    Joined:
    Jan 10, 2019
    Posts:
    2
    Hello,

    I am at a loss with this, I can easily rebind the "Interact" with the PerformInteractiveRebinding

    But on the one below, it overrides both.

    How do I rebind only one of the keys?

    Binds.PNG
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    By default, the rebind overrides any binding that matches the information it has. You can restrict things in various ways. One way with the config above would be to simply go by index.

    Code (CSharp):
    1. var rebind = sprintAction.PerformInteractiveRebinding();
    2. rebind.WithTargetBinding(1); // Override rightShift binding.
    3. rebind.Start();
    Alternatively, you could match by path.

    Code (CSharp):
    1. var rebind = sprintAction.PerformInteractiveRebinding();
    2. rebind.WithBindingMask(new InputBinding
    3. {
    4.     path = "<Keyboard>/rightShift"
    5. });
    6. rebind.Start();
     
    Last edited: Aug 19, 2019
    VoidCooper likes this.
  3. frarf

    frarf

    Joined:
    Nov 23, 2017
    Posts:
    27
    Huh, that's surprisingly robust, I like this API. Any way to add a binding instead of replacing one?
     
  4. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Code (CSharp):
    1. rebind.WithRebindAddingNewBinding();
    Accepts an optional extra argument which is the binding group to add the new binding to. So if you want to put the new binding in, say, the "Gamepad" scheme:

    Code (CSharp):
    1. rebind.WithRebindAddingNewBinding("Gamepad");