- Home /
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.
Answer by Eric5h5 · Apr 28, 2010 at 03:51 PM
Add the rigidbody component after you do the parenting.
Your answer
Follow this Question
Related Questions
I'd like to simulate a fish. 0 Answers
OnCollisionEnter of Projectile detects parent with rigidbody instead of child objects with collider 2 Answers
Trigger BoxCollider Fails to Move With GameObject After Resize 0 Answers
How do RigidBodies and Hierarchy affect child objects' colliders? 0 Answers
Collider working but not firing OnCollisionXYZ (in parent object) 0 Answers