Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Strange Issue with Rebinding - Action/Trigger is called multiple times after Rebind

Discussion in 'Input System' started by AlexHntk, Jan 27, 2021.

  1. AlexHntk


    May 6, 2015
    Hey, another head-scratcher. I've "successfully" integrated the new Input System into my project, and for the most part (knock on wood) everything is working. I noticed some odd behaviour though: If I don't rebind any controls during a play session, everything is great. If I rebind an action to a different input/button, it calls multiple times (Specifically, I am calling "if (controls.Player.Attack.triggered) ).

    I'll also just add, all the relevant actions in the ActionMaps are just type of Button, with no interactions (adding the Press Only interaction doesn't change the problem, as I guess that's the default state for a button anyways?)

    On a controller or keyboard, if I just tap the button quickly it preforms as expected. If I hold the button down for any longer than just a tap, I see an event called when the button is released as well. It's far worse with a controller trigger pull, which sees an inconsistent number of between 2 to 4 calls on activation, and another 3 to 5 on release.

    Any insight would be appreciated! I do have the following code in my ControlsManager script, though I'm currently only making use of the "canceled" / is_Pressed=false lines. Would I have better luck if I asked for input based on the is_Pressed line? I think I was trying this and ran into issues previously, hence why I'm currently calling on the triggered event.

    Code (CSharp):
    1. controls.Player.Ability1.started += context => Ability1_Pressed = true;
    2.         controls.Player.Ability1.performed += context => Ability1_Pressed = true;
    3.         controls.Player.Ability1.canceled += context => Ability1_Pressed = false;

    It's just super odd that it only happens after a rebind operation has occured, I've tried looking through my InputActionMaps and can't really come up with any reason for this behaviour.

    The code for my rebinding script is below (Caution: Extremely inexperienced and uneducated human, I apologize if any of this is ultra gross :p )

    Code (CSharp):
    1. public void RemapAction()
    2.     {
    4.         //print("TODO: Display "Enter New Key For This Action" Tooltip");
    6.         ControlsManager.controlMan.controls.Player.Disable();
    8.         rebindOperation = actionToRebind.PerformInteractiveRebinding()
    10.             .WithControlsExcluding("Mouse")
    11.             .OnMatchWaitForAnother(0.1f)
    12.             .Start();
    13.         rebindOperation.OnApplyBinding((rebindingOperation, path) =>
    14.         {
    15.             actionToRebind.ApplyBindingOverride(path);
    16.         });
    18.             ShowNewBind = true;
    19.     }
    and further down after some UI stuff;

    Code (CSharp):
    1. if (rebindOperation !=null)
    2.         {
    4.             if (Player2Rebind == false)
    5.             {
    6.                 if (rebindOperation.completed && ShowNewBind == true)
    7.                 {
    8.                     //Update Binding Graphic / String
    9.                     var bindingIndex = actionToRebind.GetBindingIndex();
    10.                     ControlsManager.controlMan.controls.Player.Enable();
    11.                     rebindOperation.OnApplyBinding((rebindingOperation, path) =>
    12.                     {
    13.                         actionToRebind.ApplyBindingOverride(path);
    14.                     });
    15.                     rebindOperation.Dispose();
    16.                     CurrentBinding.text = actionToRebind.GetBindingDisplayString(bindingIndex, InputBinding.DisplayStringOptions.DontIncludeInteractions);
    17.                     ShowNewBind = false;
    18.                     ControlsManager.controlMan.BindingRefresh();
    19.                     if (( == "grab") && isGamepad == true)
    20.                     {
    21.                         GrabBinding.text = Grab_GP.text + " +";
    22.                     }
    23.                     else if (( == "grab") && isGamepad == false)
    24.                     {
    25.                         GrabBinding.text = Grab_KB.text + " +";
    26.                     }
    27.                 }
    28.             }
    29. }
    Last edited: Jan 27, 2021
  2. AlexHntk


    May 6, 2015
    Once again, I find a solution not long after posting.. Hopefully it's helpful for me to update my queries in case others run into the same issues?

    I still can't determine what's going wrong, BUT, I did some tinkering, and it seems if I set interaction on the Action/Button to "Press only" and then change the Button Press Point to 1, it only fires once. I guess this makes sense, since the button will pass the default 0.5 press point while being pressed AND released, but it still seems odd - why does it work as desired before a rebinding, and then breaks afterwards? Oh InputSystem, you continue to baffle me :p

    edit to add: Important to change the Button to Pass Through > Button in the action map.
    Last edited: Jan 27, 2021
  3. Rene-Damm


    Sep 15, 2012
    This is an artifact of RebindOperation going and overriding *every* binding when not instructed to override a particular one. That in combination with the binding resolver happily resolving the same control however many times it was bound to the same action leads to the behavior you're struggling with.

    This has been fixed in the current develop branch (by this PR) and will roll out in the upcoming 1.1-preview.3.
    AlexHntk likes this.
  4. AlexHntk


    May 6, 2015
    Thanks for the update Rene!