i have noticed in a number of my projects that when i instantiate an object with a rigidbody and then give it a child with a collider the physics engine will sometimes ignore that collider even tho it is active. if i toggle the collider off and then on in the editor it magically starts working or if i cast a ray onto it in script it starts working. so what is causing the physics engine to ignore the collider and is there a better work around than casting rays on all of my instantiated objects to force unity to recognize that it exists?
THIS BUG HAS BEEN FIXED IN UNITY 5+ AND IS NO LONGER A PROBLEM.
I’m pretty sure there’s a few situations where changing an object in code will confuse physics. Seems like you have to “kick” it to get it to recalc values. The simplest solution is to do things the “Unity way” if you can – like Instantiate parent+child all at once (if you have 4 configurations of parents/kids, make a prefab for each.)
One thing I think I’ve had success with is what you describe doing by hand. In code, set the object inactive then active (or kinematic/non?)
After a long time of frustration and experimentation i have had some success by simply setting the rigidbody’s transform equal to null after all the colliders have been attached. that seems to be the only way to compleatly reset the collision calculations.