- Home /
Do 2d Colliders cause problems when inside nested objects in Unity?
I have some instances of prefabs on my hierarchy. They contain a child, which contains a spriteRenderer, a script and a Collider2D. The script implements the OnMouseOver method and it all works fine.
However if I create a new object, place another object inside and add a Collider2D (same structure as the prefab), my instances of the prefabs stop triggering that OnMouseOVer method.
Is the some sort of problem when adding Colliders inside the childs? Should they all be on the parents instead?
On$$anonymous$$ouseOver should work with anything you attach it to as long as it has a collider, the only ways it can't work is if something is covering it up or it's on the 'Ignore Raycast' layer.
Colliders have always worked fine on children in my experience, so there's probably a problem somewhere else. Good luck finding an answer!
Show us your hierarchy and make sure that we can easily see what's what, so name your GameObjects wisely.
If you haven't done so already, put a Debug.Log (gameObject) inside On$$anonymous$$ouseOver and remember to Collapse/Uncollapse your console messages as needed while testing.