Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 fadden · Jun 08, 2015 at 06:51 PM · androidguitouch

GUI occlusion for TouchScript on Android

I'm using Unity 5.0.2 (free).

The game I'm working on mixes Unity's Canvas-based GUI elements with 3D elements -- picture a star map that can be panned, rotated, and zoomed, with a screen-space scrollable list of stars on one side.

To avoid moving the map when scrolling through the list, I created a new TouchScript Layer, based on FullscreenLayer.cs. In the Hit method I replaced the "did I hit an object" code with this:

     EventSystem eventSystem = UnityEngine.EventSystems.EventSystem.current;
     if (eventSystem.IsPointerOverGameObject()) {
         Debug.Log("Generic gui hit: " + position);
         hit = null;
         return LayerHitResult.Hit;
     }

The Layer takes ownership of the touch by returning "Hit", but puts a null value in the out parameter that would identify the touched object. The net result is that any touch or mouse click that begins on a GUI element is ignored by TouchScript.

That worked fine on Windows, but not on Android, where IsPointerOverGameObject() never returned true. After digging through the docs for a bit, I speculatively added this:

     TouchInputModule tim = eventSystem.GetComponent<TouchInputModule>();
     if (tim.IsPointerOverGameObject(0)) {
         Debug.Log("Touch gui hit: " + position);
         hit = null;
         return LayerHitResult.Hit;
     }

This actually worked, and the behavior is exactly what I wanted: click or click-drag on GUI elements has no effect on the map, and two-finger gestures like pinch-to-zoom track across GUI elements so long as your initial touch is outside them.

My question is: why? Why was the explicit call into the TouchInputModule needed? What does the "pointerId" argument (0) mean? Is there a better way to do this? The reference documentation is a bit thin in this area.

I'm happy that I have a solution, but I worry that it'll break in the future.

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

android input problem? 0 Answers

Android touch gui help!!! 2 Answers

GUI.Button Touch Input Problem 1 Answer

Main menu touch input for android 2 Answers

Button reaction time problem 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