Search Unity

IPointerEnterHandler & IPointerExitHandler are seemingly unprecise

Discussion in 'UGUI & TextMesh Pro' started by Avalin, Sep 22, 2020.

  1. Avalin

    Avalin

    Joined:
    Oct 12, 2018
    Posts:
    98
    Hi!
    I am making a pixel art game, so every little pixel counts.
    I have made a Hover and HoverExit function utilizing Rewired for the GameObjects and it works flawlessly, down to the tiniest pixel.

    However, problems occur when I am trying to make similar code, but for UI objects instead.
    I have 2 buttons lined up next to each other, few pixels apart, and the buttons are not overlapping.

    Despite this, if I happen to have an OnPointerEnter called on either of these buttons, and I move the pointer to the other button, the OnPointerExit will not be called.


    I got my code all the way down to this:
    Code (CSharp):
    1.     public void OnPointerEnter(PointerEventData eventData)
    2.     {
    3.               Debug.Log(currentHover.name + " @ " + ReInput.controllers.Mouse.screenPosition);
    4.     }
    5.  
    6.     public void OnPointerExit(PointerEventData eventData)
    7.     {
    8.        Debug.Log("Exitted");
    9.     }
    10.  

    And I can see in the log, that the OnPointerExit is never called on this scenario.
    If I hover a button, and then stop hovering it, the OnPointerExit will be called, but not when i hover Button 2 after hovering Button 1.

    My buttons look like this:

    upload_2020-9-22_22-56-33.png

    The yellow image has Ignore Raycast on.
    Am I just missing something? Or is there a different, more precise way to check for UI raycast?
     
  2. Avalin

    Avalin

    Joined:
    Oct 12, 2018
    Posts:
    98
    To anyone else, use raycasting.
    This issue with iPointerHandlers has been unfixed for more than two years - I found a reddit thread exploring the same issue, and used the solution from there. Raycasting works perfectly.

    Found here