- Home /
(4.6 UI) Event Trigger - Pointer Exit - Not being detected if mouse moves too rapidly & calls PointerEnter
I have two triggered events, for PointerEnter & PointerExit.
Works perfectly fine, unless the mouse flies past the UI image too quickly, resulting it detecting PointerEnter, but NOT PointerExit.
Is there any easy way around this? I'm a bit surprised this breaks so easily...
I mean, besides removing PointerExit event entirely, and upon PointerEnter, trigger an Update() function to constantly check until the mouse is no longer hovering over the image.
Answer by CarterG81 · Feb 10, 2017 at 03:49 AM
Don't use OnPointerExit.
In OnPointerEnter, trigger a bool in Update() or start a Coroutine, to constantly check each frame until the mouse Is no longer hovering over the image.
How do you detect if the mouse is still on an image, if you are not considering PointerExit?
This is so old, I don't even remember. I'll have to check my code later, if I ever get around to it. The only thing I can think of right now is once it has entered, checking it is still there, and the moment the check fails disabling the bool.
I can only guess Update() or Coroutine would have logic checking if the mouse is over the image. Raycast, most likely. This logic only happens when OnPointerEnter triggers the UI, so it's fine on performance to keep checking until the check/raycast fails.
Answer by tikali23 · Jun 18, 2017 at 01:16 PM
I recently came across this problem as well when I was implementing an inventory.
In the end, I solved it by using a short HighlightManager object that is called from the OnPointerEnter and OnPointerExit methods of the highlighted UI elements.
The manager keeps track of the currently highlighted object and unhighlights it if another one also wants to be highlighted, thus an OnPointerExit Event was missed.
Your answer
Follow this Question
Related Questions
OnPointerEnter & OnPointerExit NOT WORKING 2 Answers
IPointerEnterHandler / IPointerExitHandler and touch 1 Answer
Problems with Sliding Door Animation (solved) 1 Answer
Problem with "sticking" to a block. 0 Answers
OnPointerExit doesn't work 1 Answer