UI object catches click event even by clicking outside of that object

I’m running to a weird issue where I have a Canvas and some objects on it which are adding as prefabs. Each object has a OnClick event attached to it. The problem comes in when I click somewhere in Canvas only to see one of those prefabs catch the click event (and I don’t know which one got it).

The whole thing was working good, till it wasn’t anymore. I’m not sure if I did somthing or maybe it happens after updating Unity.

Has anyone ran to this issue before or has any idea why this would happen?

UPDATE

Here’s some more details:

  • I guess the problem happened after installing Unity Pro 2017.1
  • I’ve changed the ordering layers in some different ways and problem still was around!
  • Maybe it worth mention that the prefabs are adding to a parent with grid layout group.

Hi,
Check the sorting layers of your canvas, and see which objects are higher/lower in comparison with the others. It may also be that the main Canvas area is detecting the clicks.
However, to be sure/narrow down the culprit, add this debug.log to each object’s script (the objects on the canvas, which you are trying to click:

Debug.Log("Detected Click on", gameObject);

This way, the console window in your Unity Editor, will print out the message from the clicked object, and you can tell what’s intercepting the clicks. A bit of work, but well worth it.

Good Luck!