Checking if over UI during onEndDrag - EventSystem.isPointerOverGameObject is not working as expected

I’ve built a basic drag and drop, from icons in the UI into the scene.

I’m currently having an issue with detecting if while onEndDrag the user is still over the UI as I want to block item creation.

I’m using the standard method to test if the user is still over the UI, but it is always returning true. I imagine this as the start of the drag and drop is from the UI.

  • Is there anyway to get around this?

  • Is this a potential bug?

    bool IsPointerOverGameObject(int fingerId)
    {
    EventSystem eventSystem = EventSystem.current;
    return (eventSystem.IsPointerOverGameObject(fingerId)
    && eventSystem.currentSelectedGameObject != null);

    }

Above is my C# implementation to check if the pointer is over the UI. This is called in the onEndDrag function.

public virtual void OnEndDrag(PointerEventData eventData)
{
..

if (!IsPointerOverGameObject(eventData.pointerId))

..
}

Any help would be highly recommended.

So I’ve found a solution,

Implementing both IPointerExitHandler, IPointerEnterHandler and storing IsOverUI in a private bool so I can use this to check, it’s not a perfect solution but the only usable one I’ve found.

If anyone has experienced this or solved with a more complete solution that would be great.