Search Unity

EnhancedTouch in Editor. Not recognising Touch Ended Phase.

Discussion in 'Input System' started by VOTRUBEC, Apr 23, 2020.

  1. VOTRUBEC

    VOTRUBEC

    Joined:
    Dec 17, 2014
    Posts:
    106
    I've noticed that when using EnhancedTouch in the Editor, the Input System gets confused if I start a touch in the Game window, then touch outside the Game window (the Inspector for example), then back to the Game window.

    When touching inside and outside of the game window, the Touch.onFingerDown event is triggered, with a Began phase for the Finger. But lifting my finger doesn't fire the corresponding Touch.onFingerUp event. The following finger presses result in "another" finger being pressed.

    I've tried preview 5 and 6. In both 2019.4 and 2020.1b. Seems to be the same behaviour. I'm on a Surface Pro ( a touchscreen enabled laptop ), which is why I'm able to test the touch input in the editor.

    Now, one last thing, it seems that 99.9% of the time, the onFingerUp fires correctly, but there's that odd occasion when it seems to not register the Ended phase, and thus leaves a ghost finger registered in the system. Windows itself still works fine, so my feeling is it's not the touchscreen or OS failing to report a finger up.

    Here's simple code I used to test:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem.EnhancedTouch;
    3. using Touch = UnityEngine.InputSystem.EnhancedTouch.Touch;
    4.  
    5. public class TouchInput : MonoBehaviour
    6. {
    7.     private void OnEnable ( )
    8.     {
    9.         EnhancedTouchSupport.Enable ( );
    10.         Touch.onFingerDown -= Touch_onFingerDown;
    11.         Touch.onFingerDown += Touch_onFingerDown;
    12.         Touch.onFingerUp -= Touch_onFingerUp;
    13.         Touch.onFingerUp += Touch_onFingerUp;
    14.         Touch.onFingerMove -= Touch_onFingerMove;
    15.         Touch.onFingerMove += Touch_onFingerMove;
    16.     }
    17.  
    18.     private void Touch_onFingerMove ( Finger finger ) { }
    19.  
    20.  
    21.     private void Touch_onFingerUp ( Finger finger )
    22.     {
    23.         Debug.Log ( $"Touch_onFingerUp {finger.index} : {finger.currentTouch.phase}" );
    24.         foreach ( var activeFingers in Touch.activeFingers )
    25.             Debug.Log ( $"{activeFingers.index}: {activeFingers.currentTouch.isInProgress}, {activeFingers.currentTouch}, {activeFingers.currentTouch.phase}" );
    26.     }
    27.  
    28.  
    29.     private void Touch_onFingerDown ( Finger finger )
    30.     {
    31.         Debug.Log ( $"Touch_onFingerDown {finger.index} : {finger.currentTouch.phase}" );
    32.         foreach ( var activeFingers in Touch.activeFingers )
    33.             Debug.Log ( $"{activeFingers.index}: {activeFingers.currentTouch.isInProgress}, {activeFingers.currentTouch}, {activeFingers.currentTouch.phase}" );
    34.     }
    35. }
    And here's the output after I touch in and out of the Game window a couple of times. As you can see, it simply keep adding a new finger with a incremented finger id. The previous "fingers" seem to move to alnernate positions. Not sure I'm making heads or tails of the positions. Even the timestamps are of alternating.
    https://photos.app.goo.gl/jQXguZXebyD4tSP89

    Surely this isn't "by design"? I would think either the touches down AND up are reported, or touches down shouldn't be recognised if they're outside the Game window...
     
    HattayaG likes this.
  2. herbou

    herbou

    Joined:
    Jul 8, 2018
    Posts:
    2
    Same problem