I have an unobstructed collider, we’ll call it “Collider A”, on an object with this script:
function OnMouseDown () {
Debug.Log("clicked!");
}
the scene has one camera, but the object never responds to being clicked.
It is currently a child of a rigidbody, which is a child of an empty object with a working collider “Collider B”.
If I remove the object with Collider A from those parents, the collider works… but I sort of need it nested.
Neither the rigidbody nor Collider B are obstructing Collider A, so as far as I can tell it has to do with the hierarchy.
Is there any solution other than fiddling with the parent / child situation? If so, can someone offer me an explanation to why this might be happening?
I appreciate any help, thanks.
1 Like
Hello!
Are you making sure that you are clicking the colliders with the mouse?, I mean, are you sure you are over the Object when you click them?
Remember the object has to have colliders and you have to have the mouse over the collider where the the OnMouseDown() script is attached.
Hope it helps you out :).
yes, I am certain that I am clicking down the mouse over the unobstructed collider, but thank you
Just a quick thought, have you tried to put a box collider to the object and check if it works?.
if it does then the problem is with your collider (and maybe is because you are using a mesh collider) then check the convex option on the mesh collider
Hopefully you are not trying this with a box collider! 
let me know what happens while I think more 
I am indeed using box colliders on most objects. I’ve continued my project by rearranging the hierarchy, but I would still like to avoid having to do this in the future, so I’m definitely still looking for solutions or explanations.
Thanks for trying to help me out, naruse.
Where’s the script located? If it’s on the object that’s a child, you won’t get any calls. The parent rigidbody is the only one that gets any calls when a child collider is clicked on. (As far as I know)
If you want the child to register its own calls, remove it from the hierarchy or give it its own rigidbody.
3 Likes
Yes, the script is on the child collider of the rigidbody . I wasn’t aware that a rigidbody lays claim to the colliders of its children, that’s interesting and might come in handy. That explains and solves my problem quite well, thanks!
Why is it that adding a rigidbody to a child object renders its collider ineffective and the parent object falls?
Edit: So my idea with that was to make the method of putting a detection script onto the parent object and making it something like this:
void OnMouseDown(Collider other)
{
//Then you can do something to (other.gameObject)
}
That’s not working, so my idea now is to create a RaycastHit and put “out hit” (or whatever you name the hit variable) into the parentheses after OnMouseDown, and you can mess with hit.gameObject. Hold on.
OK, that was stupid. It doesn’t recognize ray hits as a variable. However, you can fetch the GameObject attached to it in the parentheses. I think. It seems so.