Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Actions with multiple bindings workaround

Discussion in 'Input System' started by Ahmed944, Jun 13, 2021.

  1. Ahmed944

    Ahmed944

    Joined:
    Jun 24, 2018
    Posts:
    6
    Hi,
    let's say the X key performs action 1 and I have another action (action 2) with it's binding being a modifier (shift + X) and then I press shift + X, that ends up performing both action 1 and action 2.
    I know this is a limitation that hasn't been addressed yet in the new input system but do you guys have any workaround for this situation?

    Thank you in advance for your answers
     
  2. Sam_Johns

    Sam_Johns

    Joined:
    Jul 15, 2015
    Posts:
    13
    Hi Ahmed,

    There have been a few workarounds posted previously, with this first one handling button combinations via code:
    https://forum.unity.com/threads/new-input-system-arrows-with-and-without-modifier.836905/

    And then another using Composite Bindings in the InputManager window:
    https://forum.unity.com/threads/usi...n-using-the-same-binding.775109/#post-5413587

    Personally I would lean towards the first as I don't have much experience with Composite Bindings, and setting up something like:

    Code (CSharp):
    1. void OnShiftDown()
    2. {
    3.     pressingShift = true;
    4. }
    5.  
    6. void OnShiftUp()
    7. {
    8.     pressingShift = false;
    9. }
    10.  
    11. void OnXInput()
    12. {
    13.     if (pressingShift)
    14.         RunXInput1();
    15.     else
    16.         RunXInput2();
    17. }
    can be done fairly quickly, though I understand it's not ideal!
    I hope this helps!
     
    Ahmed944 likes this.
  3. Ahmed944

    Ahmed944

    Joined:
    Jun 24, 2018
    Posts:
    6
    Thanks for the reply Sam, I actually tried the first approach as it is simpler but for some reason (I'm gonna use your example to illustrate) OnXInput() runs before OnShiftDown() so I end up with the normal button pressed before the modifier can alter the boolean
     
  4. Sam_Johns

    Sam_Johns

    Joined:
    Jul 15, 2015
    Posts:
    13
    Oh that's interesting, how are your 'Shift' and 'X' inputs set up in the InputManager?
     
  5. Ahmed944

    Ahmed944

    Joined:
    Jun 24, 2018
    Posts:
    6
    I tried multiple settings and none of them worked (except the one I attached in the image). I got it working by adding a hold interaction on the single button (W) but that only worked with Pass Through action type when I tried Button action type it only worked the first time after I pressed the play button then it stopped.
     

    Attached Files:

    • 1.png
      1.png
      File size:
      33.3 KB
      Views:
      262
    • 2.png
      2.png
      File size:
      17.6 KB
      Views:
      275
    • 3.png
      3.png
      File size:
      17.4 KB
      Views:
      263
  6. Sam_Johns

    Sam_Johns

    Joined:
    Jul 15, 2015
    Posts:
    13
    ah, does that mean you've been able to fix the problem? I'm not sure what else you could try other than listing both Shift and W as separate actions, but it sounds like you might run into that 'Pass Through' vs 'Button' issue again :(
     
    Ahmed944 likes this.
  7. Ahmed944

    Ahmed944

    Joined:
    Jun 24, 2018
    Posts:
    6
    yes the problem is gone now. also listing both keys as separate actions will also be a viable solution.
    thanks for your fast replies and help it's much appreciated. :)
     
    Sam_Johns likes this.