Incorrect display of the :hover style in the simulator and on mobile devices (Android)

In the Unity Editor (in the simulator only), and on mobile devices (with Android OS), the :hover style in UI Toolkit is displayed incorrectly when switching the display of parent VisualElements.

In the following example, I have two VisualElements (Page1, Page2) containing buttons. The buttons in one element switch to the second element (using style.display). The issue is, that the :hover style remains applied to the buttons from the previously displayed page.

Desktop 2025.02.18 - 16.29.02.10.mp4 [video-to-gif output image]

Style:

Button:hover {
    background-color: rgb(255, 0, 0);
}

Template:

<engine:VisualElement name="Page1">
    <engine:Label text="Page 1" />
    <engine:Button text="Button" />
    <engine:Button text="Button" />
    <engine:Button text="Button" />
    <engine:Button text="Button" />
</engine:VisualElement>
<engine:VisualElement name="Page2" style="display: none;">
    <engine:Label text="Page 2" />
    <engine:Button text="Button" />
    <engine:Button text="Button" />
    <engine:Button text="Button" />
    <engine:Button text="Button" />
</engine:VisualElement>

Script:

public class UIBug : MonoBehaviour
{
    private VisualElement page1;
    private VisualElement page2;

    private void OnEnable()
    {
        var visualElement = GetComponent<UIDocument>().rootVisualElement;
        page1 = visualElement.Q("Page1");
        page2 = visualElement.Q("Page2");
        AssignClickAction(page1, () => { page1.style.display = DisplayStyle.None; page2.style.display = DisplayStyle.Flex; });
        AssignClickAction(page2, () => { page2.style.display = DisplayStyle.None; page1.style.display = DisplayStyle.Flex; });
    }

    private void AssignClickAction(VisualElement element, System.Action clickAction)
    {
        var buttons = element.Query<Button>().ToList();
        foreach (var button in buttons)
            button.clicked += clickAction;
    }
}

Sorry to be that guy, but could you report it using the in-Editor Bug Reporter? This is indeed a bug from what I can tell.

Hi, I reported the bug through the in-editor bug reporter as well, including a minimal project (IN-95580). I created this thread because the issue can be described more thoroughly and in detail here, and I also included a link to this thread in the bug report.

1 Like