OnPointerDown doesn't work consistently with OnDrag

First off, I am using the Input System. I am encountering what appears to be a bug that occurs when both of these criteria are met:

  1. Dragging a GameObject using the DragHandler interface.
  2. There is a different GameObject under the cursor that is below the dragged object in the hierarchy.

In this case, PointerDown events are not triggered on the object being dragged. To clarify:

  1. I’m dragging with left click and calling OnPointerDown with right click.
  2. OnPointerDown works if there is nothing below the dragged object in the hierarchy.
  3. This occurs regardless of whether or not the object below the dragged object implements IPointerDownHandler (in fact, it happens even on objects with no attached scripts).

This seems like a bug because objects that do not implement IPointerDownHandler seem to be intercepting inputs and blocking them for objects that do implement it.

I am exclusively using UI objects (Panels, Images, and TMP text) on a Screen Space Overlay canvas.

        public void OnDrag(PointerEventData eventData)
        {
            transform.position = eventData.position;
        }

        public void OnPointerDown(PointerEventData data)
        {
            if (data.button == PointerEventData.InputButton.Right)
            {
               Debug.Log("pointer down");
            }
        }

EDIT: Disabling Raycast Target on the interfering objects does not fix this issue; however, adding a Canvas Group and disabling Block Raycasts does appear to fix it.

Do the objects all have colliders?

The objects are UI Panels. They have a rect transform, a canvas renderer, and an image.

Are the raycast targets on? I seem to recall that matters

It seems the problem was that objects with a Sibling Index lower than the dragged object were blocking raycasts, even if they have no Input scripts and are transparent (as was the case here).

I edited my original post: “Disabling Raycast Target on the interfering objects does not fix this issue; however, adding a Canvas Group and disabling Block Raycasts does appear to fix it.”

1 Like

Hey, glad you found a reason… UI type elements can be problematic for that…

hey bugfinders, how are you? I have a problem about UI can you check it out pls :slight_smile:

You should bother making your own thread not hijack someone elses.

But it sounds like you are missing the eventsystem

1 Like