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?
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.
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.
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.
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.
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.
public class HoverDropdown : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
[SerializeField]
private GameObject[] _dropdownItems;
public Button[] Buttons;
private void Start()
{
OnPointerExit(null);
Buttons = GetComponentsInChildren<Button>(true);
foreach (Button but in Buttons)
{
ButtonClose bc = but.gameObject.AddComponent(typeof(ButtonClose)) as ButtonClose;
bc.hoverDropDown = this;
}
}
public void OnPointerEnter(PointerEventData eventData)
{
foreach (GameObject item in _dropdownItems)
{
item.SetActive(true);
}
}
public void OnPointerExit(PointerEventData eventData)
{
if (eventData != null)
{
if (eventData.pointerCurrentRaycast.gameObject != null)
{
if (eventData.pointerCurrentRaycast.gameObject.transform.IsChildOf(transform))
{
return;
}
}
}
foreach (GameObject item in _dropdownItems)
{
item.SetActive(false);
}
}
}
public class ButtonClose : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
public HoverDropdown hoverDropDown;
public void OnPointerEnter(PointerEventData eventData)
{
hoverDropDown.OnPointerEnter(eventData);
}
public void OnPointerExit(PointerEventData eventData)
{
hoverDropDown.OnPointerExit(eventData);
}
}
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?
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
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.
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?