How do I find which object is EventSystem.current.IsPointerOverGameObject detecting?

I am using EventSystem.current.IsPointerOverGameObject in a script and Unity returns True even though I would swear there is no UI/EventSystem object beneath the pointer.

How can I find information about the object the EventSystem is detecting?

Duplicating my answer here as well.


I’ve stumbled upon this thread and wasn’t quite happy with the solution provided, so here’s another implementation to share:

public class StandaloneInputModuleV2 : StandaloneInputModule
{
    public GameObject GameObjectUnderPointer(int pointerId)
    {
        var lastPointer = GetLastPointerEventData(pointerId);
        if (lastPointer != null)
            return lastPointer.pointerCurrentRaycast.gameObject;
        return null;
    }

    public GameObject GameObjectUnderPointer()
    {
        return GameObjectUnderPointer(PointerInputModule.kMouseLeftId);
    }
}

Looking at the EventSystem’s editor output showing names for the GameObjects, I decided that some functionality was already there and there should be means of using it. After diving into the opened source of the forementioned EventSystem and IsPointerOverGameObject (overrided in PointerInputModule), I thought it’ll be easier to extend the default StandaloneInputModule.

Usage is simple, just replace the default one added on the scene with the EventSystem and reference in code like:

private static StandaloneInputModuleV2 currentInput;
private StandaloneInputModuleV2 CurrentInput
{
    get
    {
        if (currentInput == null)
        {
            currentInput = EventSystem.current.currentInputModule as StandaloneInputModuleV2;
            if (currentInput == null)
            {
                Debug.LogError("Missing StandaloneInputModuleV2.");
                // some error handling
            }
        }

        return currentInput;
    }
}

var currentGO = CurrentInput.GameObjectUnderPointer();

I think you can use

EventSystem.current.currentSelectedGameObject

Example hovering or clicking on the button object.

 if (EventSystem.current.IsPointerOverGameObject () && EventSystem.current.currentSelectedGameObject != null && 
    EventSystem.current.currentSelectedGameObject.GetComponent<Button> () != null )
     {
             return true;
     }

EventSystem.IsPointerOverGameObject

I hope this comment is helpful to you