Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by okkal11 · Dec 16, 2016 at 12:48 PM · uieventsystemtooltipcamera.mainlateupdate

ScreenToWorldPoint causing OnPointerEnter/Exit to fire multiple times

Hi, Trying to create a tooltip using Screenspace.camera - so instead of just doing mytransform.transform.position = input.mouseposition I have to do some calculations like so;

 var screenPoint = new Vector3(Input.mousePosition.x , Input.mousePosition.y);
 screenPoint.z = 10.0f; //distance of the plane from the camera
 ToolTipGO.transform.position = Camera.main.ScreenToWorldPoint(screenPoint);

The tooltip is beeing shown and follows the mouse araound perfectly, but theres a problem with multiple fireings of onPointerEnter and onPointerExit, it spams my log, and obviously causes the tooltip-gameobject to be instantiated and deleted, making it look like its flickering.

I have tried switching to diffrent Camera.main.DiffrentTypesOfFunctions (and even disabled that last line) and this fires the events as expected - 1 time, solving all issues appart from the tooltip not beeing at the mouse position...

My scripts are as follows:

 public class Tooltip : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
 {
         GameObject UIManager;
         public string _thisTooltipsString;

         void Start()
         {
             UIManager = GameObject.Find("UIManager");
         }
     
     public void OnPointerEnter(PointerEventData eventData)
         {
            
                 UIManager.GetComponent<TooltipMouseController>().CreateToolTip(thisTooltipsString);
         }
     
         public void OnPointerExit(PointerEventData eventData)
         {
             print("Fire");
             UIManager.GetComponent<TooltipMouseController>().DestroyToolTip();
         }
 }

This script is attached to every gameobject i want to contain a tooltip

Next i have this attached to my UImanager object:

     public class TooltipMouseController : MonoBehaviour
     {
         GameObject ToolTipPrefab;
         GameObject ToolTipGO;
     
         void Start()
         {
             ToolTipPrefab = Resources.Load("ToolTipPrefab") as GameObject;
         }
     
         public void CreateToolTip(string s)
         {
                 ToolTipGO = Instantiate(ToolTipPrefab);
                 ToolTipGO.transform.SetParent(GameObject.Find("Background").transform , false);
                 ToolTipGO.transform.FindChild("Text").GetComponent<Text>().text = s;
         }
     
         public void DestroyToolTip()
         {
             Destroy(ToolTipGO.gameObject);
         }
     
         void LateUpdate()
         {
             if( ToolTipGO != null )
             {
                 var screenPoint = new Vector3(Input.mousePosition.x , Input.mousePosition.y);
                 screenPoint.z = 10.0f; //distance of the plane from the camera
                 ToolTipGO.transform.position =  Camera.main.ScreenToWorldPoint(screenPoint); //This last line can be commented out, and onPointerEnter/Exit only fires once like its supposed to - but tooltip position is ofc no longer in the correct position
             }
         }
     }

So am i doing something wrong? Why does it keep fireing on LateUpdate calculations?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by wicea · Feb 16, 2017 at 04:03 PM

I faced with same issue, that my tooltip script on object fired multiple times OnPointerEnter/OnPointerExit. I was really surprised, that without using ScreenToWorldPoint and transform.TransformPoint everything works fine. After a while I discovered the cause.

I activate tooltip prefab with Image component (option "Block raycast" is turned on) in OnPointerEnter. So my mouse cursor is over tooltip prefab now and tooltip script invokes OnPointerExit and... this deactivates tooltip prefab. And this scenery repeats again and again.

In my case I fixed it just by unchecking "block raycast" option on my tooltip's arrow image. I think you have similar issue.

Comment
Add comment · Show 1 · 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 old_pilgrim · Apr 28, 2020 at 12:17 PM 1
Share

You my friend, are a genius

avatar image
1

Answer by celtcraftgames · Nov 04, 2020 at 09:23 AM

In my case, the tooltip itself was blocking raycasts and that was causing the flickering. Make sure all text and image elements of the tooltip have "Raycast Target" unchecked.

Comment
Add comment · Show 1 · 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 gotiobg · Feb 05 at 06:08 PM 0
Share

Thanks a lot

avatar image
0

Answer by okkal11 · Dec 18, 2016 at 11:02 AM

Anyone have an idea what could cause this?

Comment
Add comment · Show 1 · 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 okkal11 · Jan 03, 2017 at 05:27 PM 0
Share

Pls halp me im stuck on this :_(

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

117 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 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

When I duplicate my UI, navigation stops working 2 Answers

How to render an image always on top? Already tried some solutions 0 Answers

Multiple Built In Packages not found in script editors but working in unity. 0 Answers

detect any UI action 1 Answer

currentSelectedGameObject not work in ios. 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