Search Unity

[CLOSED] Three interactions at once

Discussion in 'Input System' started by kukurenaiz, Feb 13, 2020.

  1. kukurenaiz

    kukurenaiz

    Joined:
    Sep 12, 2017
    Posts:
    57
    [EXPLAINED HERE]
    https://forum.unity.com/threads/slow-tap-and-hold-incompatible.898874/#post-5907524


    Good Night, I'm trying to combine interactions in one of my actions, but I can't get three interactions to work.

    I've encountered this problem in two situations so far:

    Tap > Slow Tap > Hold
    Tap and Slow tap are performed, Hold is not even started. If I invert Hold with Slow Tap becoming Tap > Hold > Slow Tap,
    Slow Tap isn't performed, the third one never triggers.

    Code (CSharp):
    1. public void OnAttack (InputAction.CallbackContext context)
    2.     {
    3.         if (context.interaction is TapInteraction)
    4.         {
    5.             if (context.started)
    6.             {
    7.                 Debug.Log ("attacked");
    8.                 _player.Attack ();
    9.             }
    10.         }
    11.  
    12.         if (context.interaction is SlowTapInteraction)
    13.         {
    14.            if (context.performed)
    15.             {
    16.                 _player.ChargeAttack ();
    17.                 Debug.Log ("Charged");
    18.             }
    19.  
    20.         }
    21.  
    22.         if (context.interaction is HoldInteraction)
    23.         {
    24.              if (context.performed)
    25.             {
    26.                 _player.PlayChargeVfx();
    27.                 Debug.Log ("Holded");
    28.             }
    29.         }
    30.     }
    Press (Press Only) > Press (Release Only) > Multipress (Modified Multi tap)
    I was having a problem with the Press and Release Behavior, if I Press and Release very fast (like a tap interaction), the release is not triggered for some reason (tested with Value as a Vector2 in a 2d Composite), so I was using this setup as a workaround. And the Multipress is a custom interaction in which I just need to press the key, unlike the multitap, in which I need to release.

    the problem here is again, the third interaction (multipress) isn't being triggered.

    Code (CSharp):
    1. public void OnMove (InputAction.CallbackContext context)
    2.     {
    3.         Debug.Log(context.interaction);
    4.         if (context.interaction is PressInteraction interaction)
    5.         {
    6.             if (sendInputData)
    7.             {
    8.                 if (interaction.behavior == PressBehavior.PressOnly)
    9.                 {
    10.                     if (context.performed)
    11.                     {
    12.                         Debug.Log ("Pressed");
    13.                         _player.SetDirectionalInput (context.ReadValue<Vector2> ());
    14.                     }
    15.  
    16.                 }
    17.  
    18.                 if (interaction.behavior == PressBehavior.ReleaseOnly)
    19.                 {
    20.                     if (context.performed)
    21.                     {
    22.                         Debug.Log ("Released");
    23.                         _player.SetDirectionalInput (Vector2.zero);
    24.                     }
    25.                 }
    26.             }
    27.         }
    28.  
    29.         if (context.interaction is MultiPressInteraction)
    30.         {
    31.             if (context.performed)
    32.                 Debug.Log ("Run");
    33.         }
    34.     }
     
    Last edited: Aug 2, 2020
  2. kukurenaiz

    kukurenaiz

    Joined:
    Sep 12, 2017
    Posts:
    57
    no clue on what happened in the first case, but the second one is very strange, I'm debugging the MultiPress interaction and both performed and started are being called, but nothing is passed to the action.

    Code (CSharp):
    1.  
    2.  void IInputInteraction.Process (ref InputInteractionContext context)
    3.     {
    4.         if (context.timerHasExpired)
    5.         {
    6.             context.Canceled ();
    7.             return;
    8.         }
    9.  
    10.         switch (m_CurrentTapPhase)
    11.         {
    12.             case TapPhase.None:
    13.                 if (context.ControlIsActuated (pressPointOrDefault))
    14.                 {
    15.                     // THIS IS BEING CALLED
    16.                     m_CurrentTapPhase = TapPhase.WaitingForNextRelease;
    17.                     m_CurrentTapStartTime = context.time;
    18.                     context.Started ();
    19.                     context.SetTimeout (tapTimeOrDefault);
    20.                 }
    21.                 break;
    22.  
    23.             case TapPhase.WaitingForNextRelease:
    24.                 if (!context.ControlIsActuated (pressPointOrDefault))
    25.                 {
    26.                     if (context.time - m_CurrentTapStartTime <= tapTimeOrDefault)
    27.                     {
    28.                         ++m_CurrentTapCount;
    29.                         m_CurrentTapPhase = TapPhase.WaitingForNextPress;
    30.                         m_LastTapReleaseTime = context.time;
    31.                         context.SetTimeout (tapDelayOrDefault);
    32.  
    33.                     }
    34.                     else
    35.                     {
    36.                         context.Canceled ();
    37.                     }
    38.                 }
    39.                 break;
    40.  
    41.             case TapPhase.WaitingForNextPress:
    42.                 if (context.ControlIsActuated (pressPointOrDefault))
    43.                 {
    44.                     if (context.time - m_LastTapReleaseTime <= tapDelayOrDefault)
    45.                     {
    46.                         if (m_CurrentTapCount >= pressCount - 1)
    47.                         {
    48.                             //THIS IS BEING CALLED
    49.                             Debug.Log("performed");
    50.                             context.Performed ();
    51.                         }
    52.                         else
    53.                         {
    54.                             m_CurrentTapPhase = TapPhase.WaitingForNextRelease;
    55.                             m_CurrentTapStartTime = context.time;
    56.                             context.SetTimeout (tapTimeOrDefault);
    57.                         }
    58.                     }
    59.                     else
    60.                     {
    61.                         context.Canceled ();
    62.                     }
    63.                 }
    64.                 break;
    65.         }
    66.     }
    67.  
    if I correctly perform the action, the
    Code (CSharp):
    1. context.Performed()
    is called, but that does not reflect in the Player Input Event. If I tap once, the Multipress event is passed to the player input, but instantly canceled due to time expiration.
     
    Last edited: Feb 14, 2020