Checking Phases in New InputSystem

Unity Version: 2020.3.20f1
New Input System: Version 1.0.2 - January 21, 2021

I can print the current phase from the new input system in relation to touch.

Debug.Log("Current Phase: " + Touch.activeFingers[0].currentTouch.phase);

The code above prints “Began” which is correct.

However, if statements (booleans) always return false;

print(Touch.activeFingers[0].currentTouch.phase.Equals(TouchPhase.Began));

Why is that?

Here is the full code:-

using UnityEngine;
using UnityEngine.InputSystem.EnhancedTouch;
using Touch = UnityEngine.InputSystem.EnhancedTouch.Touch;

public class InputManager : MonoBehaviour
{
    private void Awake()
    {
   
    }

    private void OnEnable()
    {
        EnhancedTouchSupport.Enable();
        Touch.onFingerDown += Touch_onFingerDown;
        Touch.onFingerUp += Touch_onFingerUp;
        Touch.onFingerMove += Touch_onFingerMove;


    }

    private void OnDisable()
    {
        EnhancedTouchSupport.Disable();
        Touch.onFingerDown -= Touch_onFingerDown;
        Touch.onFingerUp -= Touch_onFingerUp;
        Touch.onFingerMove -= Touch_onFingerMove;
    }


    private void Touch_onFingerDown(Finger finger)
    {
       // Works fine
        print(Touch.activeFingers[0].currentTouch.phase.Equals(TouchPhase.Began));

      // does not work
        Debug.Log("Current Phase: " + Touch.activeFingers[0].currentTouch.phase);

        ///if (Touch.activeFingers.Count > 0)
        if (Input.touchCount > 0 )
        {

            if (Touch.activeFingers[0].currentTouch.phase.Equals(TouchPhase.Began))
            {

           
                    print("This is never reached");
            }

        }
 
    }

Ok, I found the bug.
“touch phase” has the same name as the old and new input systems. I explicitly used the “touch phase” of the new system and it worked.

 if (Touch.activeFingers[0].currentTouch.phase.Equals(UnityEngine.InputSystem.TouchPhase.Moved))
2 Likes