Quick answer: Track each touch by touch.touchId in a Dictionary. Index into EnhancedTouch.Touch.activeTouches isn’t stable across frames; touchId is.
Two-finger pinch works briefly, then the gesture jumps when one finger lifts and another taps. Index-based tracking lost continuity.
The Symptom
Multi-touch gestures (pinch, drag with two fingers) glitch when fingers count changes. State from finger A leaks to finger B because they swap indices.
The Fix
using UnityEngine.InputSystem.EnhancedTouch;
public class TouchTracker : MonoBehaviour
{
private readonly Dictionary<int, Vector2> _starts = new();
void OnEnable()
{
EnhancedTouchSupport.Enable();
Touch.onFingerDown += OnDown;
Touch.onFingerUp += OnUp;
}
void OnDown(Finger f) { _starts[f.currentTouch.touchId] = f.screenPosition; }
void OnUp (Finger f) { _starts.Remove(f.currentTouch.touchId); }
void Update()
{
foreach (var t in Touch.activeTouches)
{
if (_starts.TryGetValue(t.touchId, out var start))
{
Vector2 delta = t.screenPosition - start;
// per-touch logic
}
}
}
}
Dictionary keyed on touchId. State per touch survives index reordering.
Verifying
Touch test: place 3 fingers, lift one, place another. State should track by id, not by position in the list. Add Debug.Log of touchId per frame to confirm stability.
“Track by id. Index isn’t stable. Gestures hold.”
Related Issues
For OnScreenStick, see OnScreenStick. For Input action double-fire, see double-fire.
touchId is stable. Index is not.