(Case 1358924) After calling CapturePointer(), all of OnPointerXXX are not called (1.0.0-preview.16)

Hi. I found that CapturePointer() method call makes that OnPointerXXX events are not called in runtime.

Here is code sample:

class WindowDragManipulator : PointerManipulator
{
    private bool enabled;
    private Vector2 startLayoutPosition;
    private Vector3 startPointerPosition;
  
    protected override void RegisterCallbacksOnTarget()
    {
        this.target.RegisterCallback<PointerDownEvent>(OnPointerDown);
        this.target.RegisterCallback<PointerMoveEvent>(OnPointerMove);
        this.target.RegisterCallback<PointerUpEvent>(OnPointerUp);
    }

    protected override void UnregisterCallbacksFromTarget()
    {
        this.target.UnregisterCallback<PointerDownEvent>(OnPointerDown);
        this.target.UnregisterCallback<PointerMoveEvent>(OnPointerMove);
        this.target.UnregisterCallback<PointerUpEvent>(OnPointerUp);
    }

    private void OnPointerDown(PointerDownEvent e)
    {
        if (this.enabled)
        {
            e.StopImmediatePropagation();
            return;
        }

        this.startLayoutPosition = this.target.layout.position;
        this.startPointerPosition = e.position;

        this.target.CapturePointer(e.pointerId);
        e.StopPropagation();

        this.enabled = true;
    }

    private void OnPointerMove(PointerMoveEvent e)
    {
        if (!this.enabled || !this.target.HasPointerCapture(e.pointerId))
        {
            return;
        }

        var pointerDelta = e.position - this.startPointerPosition;
        var margin = this.target.layout.size * 0.5f;

        this.target.style.left = Mathf.Clamp(this.startLayoutPosition.x + pointerDelta.x, -margin.x, this.target.panel.visualTree.worldBound.width - margin.x);
        this.target.style.top = Mathf.Clamp(this.startLayoutPosition.y + pointerDelta.y, -margin.y, this.target.panel.visualTree.worldBound.height - margin.y);
      
        e.StopPropagation();
    }

    private void OnPointerUp(PointerUpEvent e)
    {
        if (!this.enabled || !this.target.HasPointerCapture(e.pointerId))
        {
            return;
        }

        this.target.ReleasePointer(e.pointerId);
        e.StopPropagation();

        this.enabled = false;
    }
}

This works perfectly with 1.0.0-preview.14, but not work for preview.16.

Also found that dragging scrollbar, slider does not work too. Of course, no problem with preview.14. Only preview.16 has the issue.

Sometimes, Unity shows warnings like this:

Hi, I’ve tried to reproduce your problem but it seems to work correctly on my side, using preview.16 along with Unity 2020.3.14f1. I’ve attached a copy of the project files. I’m able to drag my label around on the Play window using your WindowDragManipulator. Is there anything I’m missing to repro the bug?

7426349–909128–Assets.zip (8.27 KB)

@uBenoitA Hi. thanks for investigating. I found more precise condition, if the scene has EventSystem object, the issue is occurred. I attached reproducible project. In this project, if you disabled EventSystem object the dragging works correctly (you can drag any red-label), but if it is enabled, dragging is broken.

Edit: I reported this as Case 1358924.

7426634–909170–UIToolkitTest-2021.1.zip (31.2 KB)

https://issuetracker.unity3d.com/issues/pointer-events-dont-register-on-the-second-ui-panel-when-eventsystem-is-enabled

1 Like