• 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 Fragmental · Apr 22, 2018 at 04:26 PM · cursoreventsystemwaitforsecondsevent triggeringtooltip

IsPointerOverGameObject() is true for wrong object sometimes

I have some code for a tooltip UI object that I want trigger after about a half a second. It's working except that I have a bug, caused by IsPointerOverGameObject(), where sometimes the tooltip will pop up over the wrong UI object. This only happens if you move the cursor from one object to the next at a specific speed; otherwise it works perfectly. But it happens way more often than I would like.

The code looks like this:

     public void OnPointerEnter(PointerEventData eventData)
     {
         StartCoroutine(WaitToPop());
         Debug.Log(name+ " OnPointerEnter");
 
     }
 
     public void OnPointerExit(PointerEventData eventData)
     {
         Debug.Log(name + " OnPointerExit");
         toolTipPanel.SetActive(false);
     }
 
     IEnumerator WaitToPop()
     {
         yield return waitTime;
         if (EventSystem.current.IsPointerOverGameObject())
         {
             Debug.Log(name + " IsPointerOverGameObject()");
 
             panelText.text = tooltipText;
             toolTipPanel.transform.position = tooltipPosition;
             toolTipPanel.SetActive(true);
 
         }
     }

The console looks like this: ScreenShot of Debug.Log

And here is a gif of the offending code in action: alt text

If necessary, I can upload a simple version of the project somewhere.

hoveroverbug.gif (44.1 kB)
Comment
Add comment · Show 2
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 JxWolfe · Apr 22, 2018 at 04:57 PM 0
Share

Have you thought of using a event trigger to activate a on exit and on enter function? Or would you not be able to engage the script?

avatar image Fragmental JxWolfe · Jul 13, 2018 at 08:38 AM 0
Share

@JxWolfe Sorry for the late response. $$anonymous$$y gmail account was pushing all my emails from unity over to "promotions" so I never saw them. I'll try to look at this and see if it's possible.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Fragmental · Apr 22, 2018 at 05:01 PM

I got it working correctly by using a bool instead of IsPointerOverGameObject() so fixed code reads:

     public void OnPointerEnter(PointerEventData eventData)
     {
         StartCoroutine(WaitToPop());
         Debug.Log(name+ " OnPointerEnter");
         hasExited = false;
 
     }
 
     public void OnPointerExit(PointerEventData eventData)
     {
         Debug.Log(name + " OnPointerExit");
         toolTipPanel.SetActive(false);
         hasExited = true;
 
 
     }
 
     IEnumerator WaitToPop()
     {
         yield return waitTime;
         if (!hasExited)
         {
             Debug.Log(name + " IsPointerOverGameObject()");
 
             panelText.text = tooltipText;
             toolTipPanel.transform.position = tooltipPosition;
             toolTipPanel.SetActive(true);
 
         }
     }

but I still have no idea why IsPointerOverGameObject() is weird like that

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Related Questions

Setting up EventTrigger programmatically for GameObject throws NullReferenceException 0 Answers

How to pass a click through a button? 1 Answer

Can't fire a Custom Event on UI Button Touch OnClick 1 Answer

get object that uses the event trigger 1 Answer

[BUG maybe] [picture acctached] Event Trigger component does not display the Event Type added from script 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