Search Unity

New Input System Hold Interaction doesn't reset.

Discussion in 'Input System' started by Peruman95, Aug 28, 2020.

  1. Peruman95

    Peruman95

    Joined:
    Aug 28, 2020
    Posts:
    1
    So I am using the hold interaction with the new input system on a button. However, it doesn't seem to reset. I am using the event based system and every time I hold the button it calls this function :

    Code (CSharp):
    1. public void Action(InputAction.CallbackContext context) {
    2.         print(context.started + "," + context.performed + "," + context.canceled);
    3.         if (context.performed) {
    4.             print("test");
    5.         }
    6.     }
    It seems to be working; once I press the key it prints "true,false,false", and after the correct time it prints "false,true,false" then "test". However, once that happened, if I hold the key again, nothing happens. If i understood correctly, once I release the key it should call the method with canceled = true, but that never happens. Then, once I click the play button and stop the testing, it finally prints "false,false,true" and obviously, the program stops. I have also tried calling "context.interaction.Reset();" after printing test, but nothing changed.
    I don't know if this is an issue with the editor and if playing on a build would fix it (I doubt it, doesn't seem convenient) or if I understood something incorrectly or if this is simply a bug, but right now I don't seem to be able to use the Hold interaction.
     
    domangorilla, phcoliveira and Oc7i like this.
  2. unity_N7zkzSHCoLdMLg

    unity_N7zkzSHCoLdMLg

    Joined:
    Aug 18, 2020
    Posts:
    1
    I have the same problem. Scratching my head about this.
     
  3. kren3

    kren3

    Joined:
    Jul 27, 2015
    Posts:
    1
    Same problem... Think this might be a bug. I'm on unity version 2019.4.9f1 and input system version 1.0.0.
     
  4. Oc7i

    Oc7i

    Joined:
    Oct 27, 2015
    Posts:
    3
    Can confirm this problem is still happening in Unity 2020.1.8
     
  5. SurprisedPikachu

    SurprisedPikachu

    Joined:
    Mar 12, 2020
    Posts:
    84
    I have the same problem. Unity 2019.3.15
     
  6. SurprisedPikachu

    SurprisedPikachu

    Joined:
    Mar 12, 2020
    Posts:
    84
    I found the fix. In the HoldInteraction script, replace
    Code (CSharp):
    1.             if (context.timerHasExpired)
    2.             {
    3.                 context.PerformedAndStayPerformed();
    4.                 return;
    5.             }
    with
    Code (CSharp):
    1.             if (context.timerHasExpired)
    2.             {
    3.                 if (context.ControlIsActuated())
    4.                 {
    5.                     context.PerformedAndStayPerformed();
    6.                 }
    7.                 else
    8.                 {
    9.                     context.Waiting();
    10.                 }
    11.                
    12.                 return;
    13.             }
     
    holycowproductions likes this.
  7. holycowproductions

    holycowproductions

    Joined:
    Jun 8, 2016
    Posts:
    6
    I observed that if you have multiple bindings (gamepad, keyboard etc.) for an input action which has a Hold interaction, then it malfunctions and doesn't return back to "Waiting" phase after releasing the key. If you have a single binding, the action goes back to the waiting phase.

    Could be a bug from Unity.
     
  8. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    It's not a bug, this is the result of Control Disambiguation which is explained clearly in the docs for Hold Interaction. See this snippet from the Process() description:

    The interaction cannot function properly unless Process() is called, having multiple bindings under the "Button" type Action means certain inputs will be ignored and thus the interaction will remain softlocked. The solution, as explained in the docs, is to switch to an Action type Pass Through to eliminate the disambiguation system. I've tested it first hand on Input System 1.0 and was able to get expected behavior for Hold Interaction on multiple bindings when I used Pass Through.

    For future reference, if you're encountering what you think is a bug it would be helpful to check the docs for what you're working with. There's a lot that can be solved just by reading what the developers have explained for us.
     
  9. holycowproductions

    holycowproductions

    Joined:
    Jun 8, 2016
    Posts:
    6
    Oh I will try it again with the "Pass through" action type. Thanks for bringing to my notice.