Windows Multitouch Fail

Sorry in advance for the long post, but I promise it’s an entertaining read :stuck_out_tongue:

I’m encountering a real strange issue with multi-touch input on a Windows 10 tablet.

Firstly, a bit of background… The following method builds a Dictionary of Touches organised by the GameObjects that they are touching:

public Dictionary<GameObject, List<Touch>> TouchedObjectsWithTouches()
{
	Dictionary<GameObject, List<Touch>> objs = new Dictionary<GameObject, List<Touch>>();

	// MULTI-TOUCH INPUT
	for (int i = 0; i < Input.touchCount; i++) 
	{
		RaycastHit2D hit = Physics2D.Raycast (
			Camera.main.ScreenToWorldPoint(Input.GetTouch(i).position), 
			Camera.main.transform.forward
		);
		GameObject hitObj = hit.transform.gameObject;
		if (hitObj != null)
		{
			if (!objs.ContainsKey(hitObj))
				objs[hitObj] = new List<Touch>();
			objs[hitObj].Add(Input.GetTouch(i));
		}
	}
	return objs;
}

For example, with 3 touches on object “A”, and 2 touches on object “B”, the resulting Dictionary would look something like this:

A : { Touch0, Touch1, Touch2 }
B : { Touch3, Touch4 }

The order of touches doesn’t matter.

Now, this all works absolutely perfectly on Android. Unfortunately, the people I’m doing this project for want it to run on both Android and touch-capable Windows devices.

When I make the build and test it on the Windows device, it doesn’t identify the touched objects correctly. Using the same example as above, with 3 touches on “A” and 2 touches on “B”, the resulting Dictionary looks like this:

A : { Touch0, Touch1, Touch2, Touch3, Touch4 }

If I then slide all of the touches on “A” onto “B”, the dictionary DOESN’T CHANGE. It’s still reporting that all 5 touches are on “A”, when they clearly aren’t. What gets stranger is that when there’s only 1 touch, the thing works fine - put a finger on “A” and dictionary has A : { Touch0 }, slide that touch to “B” and dictionary changes to B : { Touch0 }

But wait, there’s more!

Lets say all the touches start on “A” ( A : { Touch0, Touch1, Touch2 } ), I slide all the touches onto “B” and the dictionary doesn’t change. But I keep sliding those touches until they’re waaaay away from “A”, and finally the dictionary updates to B : { Touch0, Touch1, Touch2 }

BUT WAIT… THERE’S MORE!

Again, say the touches start on “A” ( A : { Touch0, Touch1, Touch2 } ), and I add another touch waaaay over where I got the touches to work last time. What do you think happens then? B : { Touch0, Touch1, Touch2, Touch3 } of course! Never mind the fact that 3 of the touches ARE STILL ON “A”. LOGIC!

Okay, but seriously… what the heck is this? I’m pretty sure there isn’t anything wrong with my code - at least it doesn’t look like it. I mean, it works absolutely perfectly on Android…

Any ideas? At all?

Thanks in advance.

Alright. Problem solved.

After all this, it turns out that somewhere else in the code I was using Input.touchSupported to check whether to use touch or mouse input… This always returns false on Windows devices, regardless of whether or not they actually do support touch.

Thanks Unity.

Anyway, getting rid of that solved the issue and now the multitouch works as expected on both Android and Windows tablets! Wew!