input event consumed by image raycast target that is “under” a sprite with a 2D collider

Hello everyone.

I am having a hard time getting my UI to work.

Basically I have a canvas with a UI image that is the size of the screen. This image has raycast enabled and if effectively receiving inputs.

Not in the canvas I have a sprite that have a 2D collider attached to it. No matter what I try, the UI image is always consuming the input event when I click on the sprite.

When I disable the image, the sprite gets the events, so the setup looks right (camera with Physic2D raycaster for the sprite, layerMask set to the layer of the sprite, canvas with Graphic raycaster for the image, no blocking object, no mask).

What do I need to do so that the sprite gets the input event BEFORE the image and consume it?

Sounds like you are using a graphics raycaster, instead of a physics2d raycaster for 2d colliders?

Anyways checked the Unity - Scripting API: UI.GraphicRaycaster.Raycast, you can always create a list of raycastresults and just check if it is in the list apparently

            //Create a list of Raycast Results
            List<RaycastResult> results = new List<RaycastResult>();

            //Raycast using the Graphics Raycaster and mouse click position
            m_Raycaster.Raycast(m_PointerEventData, results);

            //For every result returned, output the name of the GameObject on the Canvas hit by the Ray
            foreach (RaycastResult result in results)
            {
                Debug.Log("Hit " + result.gameObject.name);
            }