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
1
Question by NickP_2 · Jun 17, 2015 at 10:34 AM · guieventsystem

eventSystem.IsPointerOverGameObject for mobile devices

I have the following code to prevent a raycast from being cast into the 3d world when my mouse is on a uGUI element.

   if (!GUIController.Instance.eventSystem.IsPointerOverGameObject())
   {
      //raycast here on mouse click
   }

Works perfectly for editor, but when I build for iOS, it doesn't work. Does anyone has a solution for this? Thanks

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

1 Reply

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

Answer by fafase · Jun 17, 2015 at 10:49 AM

 private int fingerID = -1;
 private void Awake(){
 #if !UNITY_EDITOR
     fingerID = 0;
 #endif
 }

 // Elsewhere

 if (!GUIController.Instance.eventSystem.IsPointerOverGameObject(fingerID))
 {
   //raycast here on mouse click
 }

The method gets a default value of -1 when none is passed, and that default value is not the same as the one needed for mobile, 0.

With this code, you have nothing to do when you pass from editor to mobile thanks to the macro (if you need standalones then you need to add them).
At least I had the same issue with another similar method (IsPointerOverGameObject) and that fixed it.

Comment
Add comment · Show 4 · 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
avatar image NickP_2 · Jun 17, 2015 at 10:53 AM 0
Share

Thanks for the quick answer, Fafase. I'll let you know how it worked in the next iOS build.

avatar image Vjosey · Jan 23, 2016 at 08:44 PM 0
Share

Worked for me on Android thanks.

avatar image lasdoo5 · May 19, 2018 at 06:54 PM 0
Share

not worked it for me for android :(

avatar image fafase lasdoo5 · May 23, 2018 at 01:37 PM 0
Share

$$anonymous$$aybe something has changed in the API. Try the example from the documentation:

https://docs.unity3d.com/ScriptReference/EventSystems.EventSystem.IsPointerOverGameObject.html

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

23 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 avatar image avatar image avatar image

Related Questions

Default Event Handler 1 Answer

UGUI keyboard navigation direction for different sounds 1 Answer

UI: Mouse events not working 1 Answer

UGUI Event won't trigger on empty object 1 Answer

Event System not working with dynamically instantiated objects 0 Answers


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