Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug On Pointer enter triggering twice

Discussion in 'Editor & General Support' started by tomoaki98, Sep 26, 2022.

  1. tomoaki98

    tomoaki98

    Joined:
    Dec 19, 2017
    Posts:
    3
    I've noticed that for any script using On Pointer Enter Handler, the on enter event is triggered twice when a children graphic blocks raycast. E.g I have a children image that is within a parent image with the pointer handler script. both image blocks raycast. On entering the parent image, pointer enter event is triggered, On entering the children image, On Enter is triggering again.

    This issue extends out to buttons where it goes from Highlighted -> Normal -> Highlighted state.

    Any idea how to prevent this issue from happening? (other than disabling raycast for all children objects)
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    Is there a good reason you're ruling this out?
     
    Kurt-Dekker likes this.
  3. tomoaki98

    tomoaki98

    Joined:
    Dec 19, 2017
    Posts:
    3
    I was wondering if there was a more elegant way of resolving this issue.

    Disabling raycast on children graphics doesn't cause an issue currently with my current projects, but was just trying to account for possible future use cases where we want the children to block raycast.
     
  4. karliss_coldwild

    karliss_coldwild

    Joined:
    Oct 1, 2020
    Posts:
    530
    What version of unity are you on? There was a range of versions ~2021.3.x-2021.3.6 and probably 2022 series as well where Unity tried to change how pointer enter/exit events work for child elements. Don't remember precisely the first one where it started, but i don't think it was present in first few of 201.3.x. More or less you would get additional mouse enter/exit events when transitioning between parent and child with some flags set. But after complains from a lot of people that the change breaks their UI (including firsty components created by Unity) the default behavior was changed back to what it was before. You can still get the new behavior by setting an option (although not sure if anyone wants that).
     
  5. tomoaki98

    tomoaki98

    Joined:
    Dec 19, 2017
    Posts:
    3
    I'm on version 2021.2.10f1. Do you know which version did they revert back the behaviour so that I can do some testing on my side?
     
  6. iLinaza

    iLinaza

    Joined:
    Feb 23, 2019
    Posts:
    23
    I think that since that change that Unity introduced, you can tell if the event is reentering a children, or completely leaving your whole graphics hierarchy with the data that PointerEventData paramter gives you.

    Code (CSharp):
    1.  
    2.         public void OnPointerExit(PointerEventData eventData) {
    3.             eventData.fullyExited
    4.         /// Specifies in the case of a pointer exit if the pointer has fully exited the area or if it has just entered a child.
    5.  
    6.             eventData.reentered
    7.         /// Specifies in the case of a pointer enter if the pointer has entered a new area or if it has just reentered a parent after leaving a child.
    8.  
     
  7. iMobCoding

    iMobCoding

    Joined:
    Feb 13, 2017
    Posts:
    160
  8. karliss_coldwild

    karliss_coldwild

    Joined:
    Oct 1, 2020
    Posts:
    530
    The behavior was reverted back to old one in 2021.3.6 (I should have said ~2021.3.x-2021.3.5 in my previous post) . So if you are on 2021.3.10 what you are seeing is something else (unless you accidentaly changed the setting which activates the new behavior).

    Change log for 2021.3.6 contains:
    The versions mentioned in issues are a bit confusing since because either there was a regression after they fixed it first time or the "fix" broke stuff for a lot of projects, hence reverting default behavior to what it was before.
     
    Last edited: Oct 13, 2022
  9. karliss_coldwild

    karliss_coldwild

    Joined:
    Oct 1, 2020
    Posts:
    530
    @iMobCoding How is that related to pointer events. Isn't that only for move/submit/cancel events? Are you sure you didn't mean this?
    upload_2022-10-13_12-57-58.png

    By the way name 'sendPointerHoverToParent" is somewhat confusing. Since depending on whether child object also has pointer event handler, disabling it can cause amount of pointer events parent receives to increase not decrease.
     
  10. iMobCoding

    iMobCoding

    Joined:
    Feb 13, 2017
    Posts:
    160
    Yes, I messed things up. What I actually think is he triggered that bug I mentioned in the previous post...