I’m working on a test project before porting out game to visionOS and trying to replicate the touch input from Touchscreen with Apples native indirect tap gesture.
While single touches and swipes seem to work fine, tapping with both hands (like putting two fingers on the touchscreen) is very laggy. There’s a delay from 2-3 seconds until the system recognises that two touches are active. Sometimes they are recognised immediately.
The script is fairly simple:
using Touch = UnityEngine.InputSystem.EnhancedTouch.Touch;
void Update()
{
var activeTouches = Touch.activeTouches;
if (activeTouches.Count == 1) _cubeController.SwitchToBlue();
else if (activeTouches.Count == 2) _cubeController.SwitchToGreen();
}
However as mentioned above, it takes up to about 3 seconds to switch the cubes material if activeTouches.Count == 2.
Additionally, the system seems to lose track of the activeTouches when using two hands from time to time. When quickly tapping with both hands, it’s possible that the system will have touches registered, even if there aren’t any.
I’m using this as a temporary workaround instead of accessing Touch.activeTouches directly
List<Touch> _activeTouches = new List<Touch>();
private List<Touch> GetActiveTouches()
{
// Due to errors in PolySpatial
// Secondary touches in particular can stay in the activeTouches buffer, even when they are no longer valid
// This is a temporary workaround that handles the issue 90% of the time
var activeTouches = Touch.activeTouches;
_activeTouches.Clear();
foreach (var t in activeTouches)
{
var his = t.history;
bool valid = true;
// Check the startTime for everything in the touch history
for (int k = 0; k < his.Count; ++k)
{
if (his[k].startTime != t.startTime || his[k].touchId != t.touchId)
{
valid = false;
}
}
// If history is empty and touchphase != began this is invalid
if (his.Count == 0 && t.phase != TouchPhase.Began)
{
valid = false;
}
// If history is not empty and touchphase == began this is invalid
if (his.Count > 0 && t.phase == TouchPhase.Began)
{
valid = false;
}
if (valid)
{
_activeTouches.Add(t);
}
}
return _activeTouches;
}
I’m finding in the simulator that sometimes TouchPhase.Began isn’t called for both touches at the same time. It seems like it usually is, but then will stop doing this at random.
Ok, for me it appears to occur when the materials in the scene are darker - the bug mentioned here
I tried the fixes suggested, plus replacing xcode project, reimport all and rebooting, but no dice.
However, entering play mode in Unity, then exiting it, then replacing the xcode project did work. Will see if i can replicate that fix next time it occurs.
Good to hear that apparently there’s some way to workaround this. However I expect Apple and Unity to provide reliable input data, hopefully this will be fixed in near future