Changing scale of an UIElement calls PointerOutEvent

Hello, I’m using Unity 6000.0.3f1 (although the problem is also on previous versions).

On Android Profile, UIToolkit used on Runtime. I wonder if it’s a regular behaviour for a VisualElement, which has registered the PointerOutEvent CallBack, to trigger this event when its scale changes ?

It’s very easy to reproduce.
Starting with an empty project, create a document with a VisualElement called RedElement and register these Callbacks :

public class PointerOutBug : MonoBehaviour
{
    private VisualElement myElement;

    private void Start()
    {
        var document = GetComponent<UIDocument>();
        myElement = document.rootVisualElement.Q<VisualElement>("RedElement");
        myElement.RegisterCallback<PointerOverEvent>(OnPointerOver);
        myElement.RegisterCallback<PointerOutEvent>(OnPointerOut);
    }

    private void OnPointerOver(PointerOverEvent evt)
    {
        Debug.Log("OnPointerOver");
        myElement.AddToClassList("activated");
    }

    private void OnPointerOut(PointerOutEvent evt)
    {
        Debug.Log("OnPointerOut");
        myElement.RemoveFromClassList("activated");
    }
}

The default USS style associated is the .red class. PointerOver sets the activated class to the element :

.red {
    flex-grow: 0;
    width: 20%;
    height: 20%;
    background-color: rgb(128, 0, 0);
    align-self: auto;
    justify-content: flex-start;
    align-content: auto;
    align-items: auto;
}

.activated {
    background-color: rgb(0, 0, 128);
    scale: 0.9 0.9;
}

If you delete the scale line on .activated class, the background-color changes perfectly into blue when the pointer is on the Element (it means Touch is down). With scale: 0.9 0.9, not, because of the PointerOutEvent.

Thank you

This is by design, the PointerOverEvent takes the transform into account when determining if the event takes place. If a transform occur on the element that makes the pointer outside its bounds, a pointer-out event will be triggered.

Thank you for your answer ! If I replace in the USS class “scale : 1.5 1.5;” instead of “scale : 0.9 0.9”, the event is still triggered, although the pointer is inside the bounds (can be reproduced with code in my question). So I miss something ?

Important remark : the bug is not here when running with Windows platform, it works perfectly fine. It’s happening when running with Android platform on Unity Simulator, and also on physical Android devices and Android emulators.

Thank you

This doesn’t seem right. It would be worth filing a bug report (Help > Report a Bug…). Make sure to mention that this only seems to occur on the Android platform. Thank you!

Hello.
Was this ever fixed?
I’m facing this right now with latest Unity 6 and this is absolutely nuts.
Any changes in transform of the object triggers the pointer leave event (even if you change it, for example, by 0.0001).

It’s not clear to me if this is the same issue, but it sure feels like a bug. Please file a ticket (Help > Report a Bug) so that we can track this.

Reported as IN-94642.

1 Like