Do rigidbodies look for colliders in grandchildren [solved]

That seems to be the behaviour I’m seeing but maybe I’m doing something wrong.

Short question - Do rigidbodies only use (compound) colliders in their immediate children or should they search down the entire heirachy for colliders? Can you make them do it?

More detailed info - I have a character model imported from somewhere (3dsmax I think) and I’m moving it around manually and playing animations when needed.

The model is set up like normal I think.

Base    
  -> Pelvis         
    -> Spine
      -> L Thigh
      -> R thigh

ect.

What I want to do is have this character knock things over in the scene when it moves around. So I attached a kinematic rigidbody to the base element, and I have a script on that that listens for collision events.

Then I add simple sphere or capsule colliders to a few of the joints. Like one on each leg, foot, arm, hand etc.

Now, it seems that a rigidbody will only use the colliders that are in it’s immediate children, rather than searching down the heirachy to find all the colliders that exist.

Is that correct? When I put a big box collider on the Pelvis element (directly under the object with the rigidbody and script) it seems to work, but when the colliders only exist much further down the chain (feet etc) I get no collisions.

A rigidbody incorporates colliders on all its descendants, not just immediate children. However, colliders added after gameplay starts will not be registered and colliders on moving child objects will not necessarily give the right effect. If you are adding colliders after startup, you can ensure they are recognised by using Destroy on the existing rigidbody and adding a new one with AddComponent:-

Destroy(rigidbody);
gameObject.AddComponent(Rigidbody);

Child objects that are moved (say by an animation) might be better handled by having their own kinematic rigidbody each. Each limb can have a script that informs the root object of collisions if necessary.

Thanks for the reply andeeee

That makes sense now. Since my colliders were being moved by animations the rigidbody at the root level was not picking up their collisions.

So, it looks like putting a Kinematic Rigidbody, Collider and simple script on each limb is the way to go.

Just tested that out and it works fine. The script on the limbs just uses SendMessageUpwards to send collision messages up to the root. Fairly simple.

Cheers.