Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by eldorno · Oct 07, 2016 at 07:42 AM · inputtouchwindowsmultitouch

Windows Multitouch Fail

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

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.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image doublemax · Oct 07, 2016 at 08:25 AM 0
Share

Did you test that on different tablets? Some cheap tablets only support two distinct touches. Do you have any other mul$$anonymous$$ch demos / apps to test if the touch works correctly on that device?

avatar image eldorno doublemax · Oct 07, 2016 at 10:20 AM 0
Share

Unfortunately I only have that one Windows tablet to test it on. I know for a fact, however, that this tablet supports at least 10 simultaneous touches; earlier in development I wrote a short code snippet to display the x,y co-ordinates of each of the active touches, they all reported their individual, distinct locations correctly (and they still do). Because of this, I'm wondering if it's something related to the raycast... Either way, it's definitely not a limitation of the tablet.

Also should mention there is a separate part of this same project which requires tapping on up to 4 or 5 objects at once (tested thoroughly and successfully) - it's using a different block of code for input, though it bears some similarities to the one mentioned in the original post - and it works fine.

Edit: I just tested this other mul$$anonymous$$ch part of the project again, and now it isn't working, BUT an older build with the exact same input code does work.... Now I'm really confused x_x

avatar image eldorno eldorno · Oct 07, 2016 at 10:26 PM 0
Share

Okay... I have some further information.

Firstly, I wondered if it was caused by an asset that I had imported, but there was only one of those (LeanTween), and the problem still persisted after removing it.

After further investigation, it seems that the object that all the touches get associated with is the object that's at the average position / centrepoint of all the touches - hence why, in the above examples, when I add the touch waaaay away from object "A", it then starts reporting object "B" - "B" is now at the centrepoint of all the touches.

That also explains why it continued to report "A" when I moved all touches off "A" ... I moved them off in a circular motion, which of course left "A" as the centrepoint. If I move all touches off "A" so that they're all still near each other, then "A" stops being the reported object as it's no longer at the centrepoint.

Well, at least I know how it's selecting which object to associate the touches with... Still no idea why though.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by eldorno · Oct 12, 2016 at 06:03 AM

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!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Does unity now support multitouch directly in windows? 1 Answer

Input.GetTouch SOMETIMES not registering on iOS 0 Answers

multiTouch problem when fingers close together (Bug?) 1 Answer

I try to Create a DLL for get WM_TOUCH windows message! 1 Answer

MultiTouch issues 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges