Click detection suddenly stopped working
I'd like to start off by apologising for the overly vague question. Unfortunately, this project contains a lot of code and I have no idea which part of it could be the problem so naturally I have no idea which parts of the code to post. Let me know if there is something specific I should be posting here...
I'm posting this question to see if anyone know why this might be occurring or where I should look in my project to try and get this resolved or if anyone knows any way to debug this because this doesn't make any sense to me what so ever...
That said, here is the problem:
I have a bunch of prefabs that are instantiated at run-time and their supposed to behave a certain way when clicked (or touched since this is going to be a phone app eventually). I got this to work with OnMouseDown() no problem. After working on the project a bit and implementing things which as far as I can tell are completely unrelated this, it seems that now no matter where I click, it will detect the click as though it came from the first of the instantiated prefabs. Furthermore, when I delete that one from the editor or disable the collider, it seems to pick another at random to be the only one to detect and click and detect it even if I haven't clicked on this.
The most frustrating thing about this entire situation is that even when I revert all changes I made, I can't get it to work like it did before and I have no idea why!
So yeah, thanks for reading and thanks in advance for any help!
UPDATE: Thanks to @streeetwalker, I now realise the prefab with the lowest z value is always the one stealing clicks. Initially I made them spawn with a z value of 0, I tried changing it so that they're all unique, all positive, all negative, nothing seems to change the fact that the gameobject with the lowest z is stealing all the clicks! So bizarre that that wasn't happening before
2D. Was just working on the project. I know, this is super vague and not very helpful, but actually there were a lot of things I added in between when it stopped working and when it didn't, but like I said as far as I can tall none of them had anything to do with the prefabs or how they operate
What are thins?
2D is a bit different. Sounds like something in front is s$$anonymous$$ling clicks. If everything has the same z axis value, this is a frequent problem. What gets the $$anonymous$$ouseDown seems random.
Have you tried making sure that your objects, such as backgrounds are at different z values? I think the default is -z vlaues are closer to the camera than +z.
Answer by The-It · Mar 13, 2020 at 03:09 AM
The problem was for some reason that the edge radius on the collider in the prefab was set to an obscenely high number so it was taking up the entire canvas.