Dynamically parenting a collider object to a rigidbody object causes collision bug.

Hi, first of all.

I have two GameObject :

  • GameObject A with a Rigidbody and a CapsuleCollider.
  • GameObject B with only a CapsuleCollider.

If I do parenting object B to object A not at runtime, I obtain a fully correct compound object with a collider formed by the two capsules.

But if I try to do parenting at runtime (with the Hierarchy panel or by scripting) the result compound object has an incorrect physical behavior. Indeed, A and B are attached together but B object doesn't collide with the ground (Terrain) and hasn't infuence on the compound object physics.

Note : here the simple hierarchy

  • Object A (rigidbody, collider)
    • Object B (collider)

After somme debug tests, I found that if I do parenting B to A not at runtime, gameObjectB.collider.attachedRigidbody correspond to the rigidbody of the A object. It's ok.

But if I do parenting B to A at runtime, gameObjectB.collider.attachedRigidbody is null. This is abnormal.

Do you ever meet this type of problem and have you an idea to fix it ?

Thanks in advance for your help.

Add the rigidbody component after you do the parenting.