Search Unity

ButtonWithTwoModifiers binding triggers the performed event even though the modifier are not pushed

Discussion in 'Input System' started by poprev-3d, Feb 12, 2021.

  1. poprev-3d

    poprev-3d

    Joined:
    Apr 12, 2019
    Posts:
    72
    I'm having a problem with the new input system ButtonWithTwoModifiers composite binding that triggers the action even though the modifiers have not been pressed (Input System 1.0.1 in Unity 2019.4.17f ).

    Basically, I'm wanna to add a new shortcut (Ctrl + Shift + U) at runtime (lets say 10s after the game starts), and this shortcut is to trigger an action.

    The issue is that the composite binding action is triggered by pressing U only even though the modifiers Ctrl and Shift have not been pressed.

    Code (CSharp):
    1.              
    2. InputActions actions = ...;
    3.  
    4. //Disables the input actions temporally
    5. actions.Disable();
    6.  
    7. //Gathers our action map
    8. InputActionMap theActionMap = actions.asset.FindActionMap("System", true);
    9.  
    10. //Create the action
    11. InputAction theCreatedAction = theActionMap.AddAction("Test action", type: InputActionType.Button);
    12.  
    13. //Add the binding to the action
    14. theCreatedAction.AddCompositeBinding("ButtonWithTwoModifiers")
    15. .With("Modifier1", "<Keyboard>/leftCtrl")
    16. .With("Modifier1", "<Keyboard>/rightCtrl")
    17. .With("Modifier2", "<Keyboard>/leftShift")
    18. .With("Modifier2", "<Keyboard>/rightShift")
    19. .With("Button", "<Keyboard>/#(u)");
    20.  
    21. //Adds the logic that would be called when the action is performed
    22. theCreatedAction.performed += ctx => { Debug.Log(ctx.ReadValueAsButton()); Debug.Log("This is performed"); };
    23.  
    24. //Re-enables the input actions
    25. actions.Enable();
    26.  
    The actual behaviour of this code: the created action is performed when I press the U key only (not Ctrl or Shift)
    Expected behaviour of this code: the created action is performed when I press Ctrl Shift U simultaneously

    It seems this composite binding works if I put this logic in the start (or awake) but not after the game started for a while.

    Any idea? Am I using the input system the wrong way?

    Thanks !
     
    zIyaGtVm and philippebedard like this.
  2. philippebedard

    philippebedard

    Joined:
    Jan 20, 2021
    Posts:
    6
    Any update on that ? I have a similar issue. Thanks...
     
  3. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    same issue here 2020.3 .InputSystem 1.0.2.

    case 1 can be performed, only need "V" is pressed
    Code (CSharp):
    1. .AddCompositeBinding("ButtonWithTwoModifiers")
    2.                 .With("Modifier1", "<Keyboard>/leftCtrl")
    3.                 .With("Modifier2", "<Keyboard>/leftShift")
    4.                 .With("Button", "<Keyboard>/v");

    case 2 can be performed, only need "shift" is pressed
    Code (CSharp):
    1. .AddCompositeBinding("ButtonWithTwoModifiers")
    2. .With("Button", "<Keyboard>/v")
    3. .With("Modifier1", "<Keyboard>/ctrl")
    4. .With("Modifier2", "<Keyboard>/shift");
     
    Last edited: Jul 28, 2021
  4. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    I found that sometimes even one key could trigger a buttonwithonemodifier binding.
     
  5. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    Still don't know what cause this problem.

    Will calling AddCompositeBinding("ButtonWithTwoModifiers") in runtime:
    ctrl+shift+f will trigger action,
    f will trigger action,
    ctrl+f will trigger action,
    shift+f will trigger action.

    However if I config a BindingWithTwoModifiers in InputActionsAsset, only ctrl+shift+f performed.

    I leave an action empty with code below.
    Code (CSharp):
    1. ...Action0.AddCompositeBinding("TwoModifiers")
    2.                 .With("Modifier1", "<Keyboard>/" + hotkeys[0])
    3.                 .With("Modifier2", "<Keyboard>/" + hotkeys[1])
    4.                 .With("Binding", "<Keyboard>/" + hotkeys[2]);
    5.  
    6.  
    7.             // ...Action0.AddCompositeBinding("TwoModifiersComposite")
    8.             //     .With("Modifier1", "<Keyboard>/" + hotkeys[0])
    9.             //     .With("Modifier2", "<Keyboard>/" + hotkeys[1])
    10.             //     .With("Button", "<Keyboard>/" + hotkeys[2]);
    11.             // ...Action0.Enable();
    asset.png

    Unity 2020.3f15 InputSystem 1.1.1
     
    Last edited: Sep 16, 2021
  6. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Hi, would you mind filing a bug report for this one? This should get looked at.
     
  7. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    Thanks for your reply, I'v sent the report.
    reported.png
     
    Rene-Damm likes this.
  8. philippebedard

    philippebedard

    Joined:
    Jan 20, 2021
    Posts:
    6
    Happy to see we aren't the only one with this issue! It seem to be always the last registered shortcuts (runtime).

    We made a small workaround by calling this code every time we register a new input at runtime. So far we don't have the issue.

    Code (CSharp):
    1.  
    2.         /// <summary>
    3.         /// Function to make the last binding work why i dont know! (To be deleted once Unity fix this issue)
    4.         /// </summary>
    5.         /// <param name="inputActionMap"></param>
    6.         private void UpdateBinding(InputActionMap inputActionMap)
    7.         {
    8.             InputAction anAction = inputActionMap.AddAction("tempAction");
    9.             anAction.AddBinding("Button");
    10.             anAction.RemoveAction();
    11.         }
    12.  
    To be honest I haven't try without my workaround with the release 1.1.1. I might give it a try next week.

    Also since you are working with shift+ctrl shortcut like I do. Be careful with this: https://forum.unity.com/threads/wrong-input-values-with-windows-shortcuts.1168457/#post-7491764
    I'm still waiting for a fix on that one.
     
    Last edited: Sep 17, 2021
    zIyaGtVm likes this.
  9. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    Really appreciate it, this workaround works for me.:)
     
    philippebedard likes this.
  10. philippebedard

    philippebedard

    Joined:
    Jan 20, 2021
    Posts:
    6
    Any update on this issue?