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.

iPointerExit and Child Objects

Discussion in 'UGUI & TextMesh Pro' started by TenEightCME, Oct 31, 2021.

  1. TenEightCME

    TenEightCME

    Joined:
    Jun 5, 2016
    Posts:
    5
    Hi there,

    I recently made the poor decision to update unity from 2020.3.21f1 to 2021.2.0f1. I'm not sure what exactly changed but my project is now functioning very differently than before the update. I'm guessing that it might have something to do with the new input manager.

    My project has a UI dropdown menu. Clicking the menu causes the dropdown to expand. If the dropdown is expanded and the cursor leaves it, the dropdown collapses.

    The dropdown menu is as follows:

    Dropdown parent
    - Child dropdown content (buttons, scrollbar, background, etc that expand)
    - Child dropdown button image

    The parent object contains only the script while both children have no script but have images/buttons within them.

    In 2020.3.21f1, the dropdown worked as I intended. Unity seemed to consider the parent object and its children to be all one blob. When the cursor was over any of the children, OnPointerEnter was triggered on the parent and when the cursor exited any of the children, OnPointerExit was triggered on the parent.

    Since upgrading to 2021.2.0f1, it seems as if each of the children are being treated as independent objects. Moving the cursor between child objects (but still within the overall parent object) triggers an OnPointerExit and OnPointerEnter for each child object.

    I don't want OnPointerExit to be triggered when the cursor moves between the two child objects within the parent and I only want it to trigger when the cursor leaves the overall parent object. Was there some sort of change between 2020.3.21f1 and 2021.2.0f1 that is responsible for this change in behaviour?
     
  2. Master_Aricitic

    Master_Aricitic

    Joined:
    Sep 17, 2017
    Posts:
    6
    I had a similar problem, but mine was trying to close a dynamically built menu when the mouse leaves it.
    I was using a box collider to allow the OnPointerOver and OnPointerExit functions to work.

    Just now I discovered that when adding these colliders to GUI objects they are created as a 10x10 box square at the center of the object, and NOT at the size of the object they are attached to. You also must manually fix the collider's size (under size under the Box Collider 2D's options), as I found no way to drag the edges...

    I do not know if this is what is affecting you, but it may be as the OnPointerExit should exit when it exits the Box Collider.
    Please, feel free to tell me if I'm wrong.
     
  3. Incole

    Incole

    Joined:
    May 5, 2018
    Posts:
    10
    Yes, this event in 2021.2 change behaviour. It broke my whole UI. IPointerExit now fire when pointer is come over the child of IPointerExit holder. I don't know what to do.
     
    customphase likes this.
  4. Incole

    Incole

    Joined:
    May 5, 2018
    Posts:
    10
    You can use this for old behaviour:

    Code (CSharp):
    1.    
    2. public void OnPointerExit(PointerEventData eventData)
    3. {
    4.     if (eventData.pointerCurrentRaycast.gameObject.transform.IsChildOf(transform))
    5.         return;
    6.  
    7.         ...
    8. }
    9.  
     
    Cuisor, asimdeyaf, Shadden120 and 2 others like this.
  5. Tyrant117

    Tyrant117

    Joined:
    Aug 25, 2014
    Posts:
    8
    There really should be a breaking functionality log that gets updated and a link to view when trying to upgrade versions. This is the only post I could find about it.
     
    customphase and TenEightCME like this.
  6. TenEightCME

    TenEightCME

    Joined:
    Jun 5, 2016
    Posts:
    5
    Thanks! This replicates the old functionality quite closely!
     
    Cuisor likes this.
  7. fredrikpedram

    fredrikpedram

    Joined:
    Oct 8, 2017
    Posts:
    3
    The "eventData.fullyExited" property will return false if the pointer is over a child object.
    The code below will solve the problem :

    Code (CSharp):
    1. public void OnPointerExit(PointerEventData eventData)
    2. {
    3.     if (!eventData.fullyExited)
    4.     {
    5.         return;
    6.     }
    7.  
    8.     //...
    9. }
     
  8. Simpowitch

    Simpowitch

    Joined:
    Nov 13, 2018
    Posts:
    14
    We have the same issue in our team. And this causes issues with the Built in buttons and Toggles that changes colour or sprites depending on the cursor events. For instance hoovering a button with a text child now triggers on-pointer-enter and on-pointer-exit causing the colour or sprite-swap to go back to default even when the cursor still is "over the button" (i know that it actually is now considered over the text that is a child of the button, but come on...) Who wanted this feature?

    And to add to the discussion: This actually made it's way into the LTS version. (we only use LTS). Which means everyone who upgraded and wanted stability now gets this unexpected and weird behaviour on all of their old UI.

    -using LTS 2021.3.2f1
     
    Last edited: May 20, 2022
  9. Taobyby

    Taobyby

    Joined:
    Nov 22, 2020
    Posts:
    1
    I have the same problem while following a Tutorial for Inventories. It works fine with 2020.X but with 2021.3.x it´s broken.
     
  10. Michael_Swan

    Michael_Swan

    Joined:
    Aug 24, 2021
    Posts:
    37
    Ours was broken horribly too. The fix (for us at least) isn't as simple as above.

    I had to create a new monobehaviour (ButtonClose) to attach to all the child buttons, that called the parent hoverdropdown whenever a Enter/Exit occurred, and could not use fullyExited.

    Code (CSharp):
    1.  public class HoverDropdown : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
    2.     {
    3.         [SerializeField]
    4.         private GameObject[] _dropdownItems;
    5.  
    6.         public Button[] Buttons;
    7.  
    8.         private void Start()
    9.         {
    10.             OnPointerExit(null);
    11.  
    12.             Buttons = GetComponentsInChildren<Button>(true);
    13.  
    14.             foreach (Button but in Buttons)
    15.             {
    16.                 ButtonClose bc = but.gameObject.AddComponent(typeof(ButtonClose)) as ButtonClose;
    17.                 bc.hoverDropDown = this;
    18.             }
    19.         }
    20.  
    21.         public void OnPointerEnter(PointerEventData eventData)
    22.         {
    23.             foreach (GameObject item in _dropdownItems)
    24.             {
    25.                 item.SetActive(true);
    26.             }
    27.         }
    28.  
    29.         public void OnPointerExit(PointerEventData eventData)
    30.         {
    31.             if (eventData != null)
    32.             {
    33.                 if (eventData.pointerCurrentRaycast.gameObject != null)
    34.                 {
    35.                     if (eventData.pointerCurrentRaycast.gameObject.transform.IsChildOf(transform))
    36.                     {
    37.                         return;
    38.                     }
    39.                 }
    40.             }
    41.  
    42.             foreach (GameObject item in _dropdownItems)
    43.             {
    44.                 item.SetActive(false);
    45.             }
    46.         }
    47.     }
    Code (CSharp):
    1. public class ButtonClose : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
    2. {
    3.     public HoverDropdown hoverDropDown;
    4.  
    5.     public void OnPointerEnter(PointerEventData eventData)
    6.     {
    7.         hoverDropDown.OnPointerEnter(eventData);
    8.     }
    9.  
    10.     public void OnPointerExit(PointerEventData eventData)
    11.     {
    12.         hoverDropDown.OnPointerExit(eventData);
    13.     }
    14. }
     
    asimdeyaf likes this.
  11. iMer

    iMer

    Joined:
    May 21, 2013
    Posts:
    29
    This change has also broken lots of buttons for us and caused all sorts of visual issues (buttons being stuck in hover mode, or not hovering at all) - looks like unity broke stuff and didnt even patch their own ui components?
     
  12. MohammedOmarPF

    MohammedOmarPF

    Joined:
    May 10, 2020
    Posts:
    3
    How did you solve this? I was planning to create a new Custom Button script that inherit from the original button and modify it's IPointerExit function and if that's not possible, I would Create a new script that inherit from MonoBehavior with IPointer functions and handle the color changing and the rest of the features.

    That's really annoying that this is pushed to LTS! We have a lot of UI and upgrading seems to have more issues than fixes. Hopefully Unity adds a checkbox or something to stop this if it's not needed
     
  13. Simpowitch

    Simpowitch

    Joined:
    Nov 13, 2018
    Posts:
    14
    We still have not solved it. Waiting for Unity to patch it. It will take too much time and money to spend on and we simply hope Unity will fix this in a future version. They have reviewed my report and confirmed the errors and are working on a fix.
     
  14. GabrielWink

    GabrielWink

    Joined:
    Jun 30, 2018
    Posts:
    5
    We also have this issue with my team. It broke the behavior of most of our buttons.
    And I'm still not sure if this behavior is a bug, or intended by the new system (bad idea imho).
    Anyone from Unity who could tell us?
     
  15. chrpetry

    chrpetry

    Joined:
    Mar 7, 2018
    Posts:
    49
    I am also stuck now on this.
    Unity: Is this a regression or a really well thought-out solution for something?
     
  16. karliss_coldwild

    karliss_coldwild

    Joined:
    Oct 1, 2020
    Posts:
    378
    @chrpetry What version of Unity are you on? Unity reverted the default behavior back to old behavior in 2021.3.6 .
     
    Michael_Swan likes this.
  17. zhaozony

    zhaozony

    Joined:
    Jan 7, 2020
    Posts:
    25
    What? I just changed all my buttons and tooltips to adpat to this behaviour, .and now it's back to normal?
    Kind of in rage, to be honest.
     
  18. chrpetry

    chrpetry

    Joined:
    Mar 7, 2018
    Posts:
    49
    I also adapter some of my prefabs. I'm currently on 2022.1.18f. Is there something in the changelogs about this?
     
  19. Michael_Swan

    Michael_Swan

    Joined:
    Aug 24, 2021
    Posts:
    37
    I think they have not "undone" the fix in 2022.1.21. (Maybe they forgot?) Mine works in 2021.3.11, but not in 2022.1.21.

    Unity reverted the default behavior back to old behavior in 2021.3.6 .

    Should I make a bug fix for this ?
     
  20. PirateBridges

    PirateBridges

    Joined:
    Mar 10, 2022
    Posts:
    1
    I am on 2022.1.6f1 and I have the same issue. It completely broke my UI system for all of the tooltips, inventory menus, submenus, etc.