- Home /
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.
to catch an event some UI element has to be in that place. Check the position you've clicked at during play mode when you click it and something received the click. Reduce the amount of UI elements one by one, or start with just one and enable few more, all during play mode. You'll find it.
@hexagonius Thanks for the reply. But I did as you said and the object still catches the click wherever I click on the Canvas. I'm starting to think it as a weird bug in Unity Pro 2017.1
Do even without any UI elements active you receive a click event? Are you using the event System it the input class?
@hexagonius The problem stays until I remove the last prefab which has the script for receiving click event. After removing all those prefabs, nothing happens. I'm using IPointerClickHandler
if that's what you asked.
Answer by jtok4j · Sep 20, 2017 at 10:40 PM
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!
Your answer
![](https://koobas.hobune.stream/wayback/20220612135225im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
void dont show up in on click 1 Answer
button OnClick function triggering another buttons OnClick 0 Answers
Click on box collider on an image in a canvas 0 Answers
Canvas button with 2 functions onClick must be pressed twice for 2nd function? Will not disappear? 1 Answer
How to make it so only a certain section of a button will work on click 1 Answer