I have the following code, and I’m getting odd behavior regarding the Began phase. Sometimes it won’t be called (goes straight to Moved), other times it will be repeatedly called until I move my mouse (using Touch simulation). Stationary will only be called after the first move. It sometimes behaves as expected, however. In another script (basically the same except for some movement stuff), the “Began” phase burst will be about equal to the times it skipped.
My test code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem.EnhancedTouch;
using Touch = UnityEngine.InputSystem.EnhancedTouch.Touch;
public class TestInputs : MonoBehaviour
{
private void Awake()
{
EnhancedTouchSupport.Enable();
}
void Update()
{
if (Touch.activeFingers.Count == 1)
{
Touch activeTouch = Touch.activeFingers[0].currentTouch;
if (activeTouch.phase == UnityEngine.InputSystem.TouchPhase.Began)
{
Debug.Log("Touch started: " + Time.frameCount);
}
if (activeTouch.phase == UnityEngine.InputSystem.TouchPhase.Moved || activeTouch.phase == UnityEngine.InputSystem.TouchPhase.Stationary)
{
Debug.Log("Touch moved/stationary: " + Time.frameCount);
}
if (activeTouch.phase == UnityEngine.InputSystem.TouchPhase.Ended)
{
Debug.Log("Touch ended: " + Time.frameCount);
}
}
}
}
Console output looks like this:
Touch started: 226
Touch started: 227
Touch started: 228
Touch started: 229
Touch ended: 230
I could just write my own “Began” check, but there’s nothing to learn in doing that :). From my understanding EnhancedTouch is the one that should work with update() polling, but is there more I need to do to get that working?
Thank you!
Used this tutorial: Tutorial: Implementing touch with Input System's Enhanced Touch API
–Edit in case anyone has this issue:
I replaced Touch.activeFingers[0].currentTouch
with just Touch.activeTouches[0]
to get the expected behavior. If anyone whats going on here I’d appreciate it!