Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

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

Discussion in '2D' started by downstroypvp, Nov 9, 2019 at 12:57 AM.

  1. downstroypvp


    May 30, 2016
    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?
  2. PuppyPolice


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

    Anyways checked the, you can always create a list of raycastresults and just check if it is in the list apparently

    Code (CSharp):
    1.             //Create a list of Raycast Results
    2.             List<RaycastResult> results = new List<RaycastResult>();
    4.             //Raycast using the Graphics Raycaster and mouse click position
    5.             m_Raycaster.Raycast(m_PointerEventData, results);
    7.             //For every result returned, output the name of the GameObject on the Canvas hit by the Ray
    8.             foreach (RaycastResult result in results)
    9.             {
    10.                 Debug.Log("Hit " +;
    11.             }
    Last edited: Nov 10, 2019 at 11:32 PM