- Home /
The way Unity decides which collider is triggered seems capricious and arbitrary
I have objects within a 2D gamespace (inside the UI Canvas, if that matters), that have 2D Colliders so that I can do an OnMouseOver function. I recently added some child objects to one of them (occupying the same space in location as well as hierarchy), and the child objects also have 2d Colliders and an OnMouseOver functions.
What I just found out is that the OnMouseOver function will often trigger for the parent object when I'm mousing over the child objects. I've learned in the past that this is often because of Pos.Z, but what I found in this case is that it's actually Scale.Z that seems to be making the difference here. But what's weird is that, if I pause the game and change the parent's Scale.Z in the Inspector, then it works fine (the OnMouseOver function for the child is activated, instead of the parent's), but if I stop the game and change the parent's value, then start the game over, it won't work. But if I pause the game and change it back to the old value, then change it to the new value again, it will work.
What's even weirder is that when it's not working across the board, there always will be some child objects where the OnMouseOver does work properly for them (instead of the parent object underneath it), but not for others, even if all the child objects have the exact same Pos.Z and Scale.Z. That doesn't seem rational to me.
Your answer
Follow this Question
Related Questions
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Physics2D.Linecast ignoring walls 1 Answer
Why is OnDrag triggering but not OnMouseDown? 0 Answers
I can't manage to detect my collisions 0 Answers
Getting the Collider of a Tile 0 Answers