Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug Slow tap and Hold incompatible

Discussion in 'Input System' started by kukurenaiz, May 27, 2020.

  1. kukurenaiz


    Sep 12, 2017
    Reasking an old unanswered question (perhaps a bug).
    Apparently, Slow and Hold are incompatible, both can't be listened at the same time, at least not in the way I would expect. I'm using unity 2019.2.19f1 [Input System 1.0.0],


    I've already tried to use Button and Value instead of Passthrough, didn't help.

    Depending on their order in the Input Action Asset, Slow Tap OR Hold is called, never both. The way I'm listening to them is like this:
    Code (CSharp):
    1.         if (context.interaction is SlowTapInteraction)
    2.         {
    3.             if (context.performed)
    4.             {
    5.                 player.ChargeAttack ();
    6.             }
    7.         }
    9.         if (context.interaction is HoldInteraction)
    10.         {
    11.             Debug.Log("is holding");
    12.             if (context.started)
    13.                 Debug.Log ("started holding");
    14.             if (context.performed)
    15.             {
    16.                 Debug.Log ("Holded");
    17.             }
    18.         }
    If I release the button before the hold time ends, the interaction is executed.
    If I release after the time has passed (it should already have been performed), nothing happens and the 'is HoldInteraction' condition is never met.
    Last edited: May 27, 2020
  2. Rene-Damm


    Unity Technologies

    Sep 15, 2012
    The way the stack works with this setup and in fact the rather subtle difference between a "hold" and a "slow tap" makes this one confusing. Both of these issues we plan to address.

    The key problem here is that the slow tap and the subsequent hold lead to an ambiguous situation...

    ... with this being the expected outcome.

    Confusingly, the way these two interactions work right now, a hold is essentially equivalent to a slow tap except for the minor difference that a hold triggers while the button is still down (i.e. "trigger when the button is held for X amount of time") whereas a slow tap triggers when the button is released (i.e. "trigger when the button is released after being held for X amount of time").

    With durations for both interactions set to 1 second as in your setup, the hold will never get a chance to actually perform.
    1. Button is held for <1s. Will start slow tap on button down (first interaction in stack), then cancel the slow tap on button release (interaction cannot be completed), control passes to hold interaction (that's what you're seeing in your code), but then hold immediately cancels, too. It's probably confusing that the hold is started at all but from the POV of the input system, it is perfectly conceivable that the subsequent interaction is fine completing on the button release. So it will give the interaction a shot at handling the input -- which in this case will lead to a second aborted interaction. At this point, control will pass on to Tap -- if the button was released within 0.2s, it will perform a tap, otherwise it'll cancel, too.
    2. Button is held for >1. Regardless of when the button is eventually released, Slow Tap will not let control pass on to the hold interaction.
    Aside from the interaction stack being confusing in its operation, we hope to improve on how the interactions are defined. And we hope to make the working of interactions more visible in some visual fashion in the editor.
    kukurenaiz likes this.
  3. kukurenaiz


    Sep 12, 2017
    thank you very much. currently using two actions as a workaround.