Hi everybody,
in my scene i need to attach to my 3D model a collider component with rigidbody to catch some collisions. I attached box colliders to my model and then a rigidbody component. After the collisions are catched i dont need rigidbody component anymore. And i need to change box colliders to mesh colliders.
if (model.transform.childCount != 0) {
for (int i=0;i<model.transform.childCount;i++) {
if (model.transform.GetChild(i).gameObject.GetComponent<MeshRenderer>()!=null) {
GameObject.Destroy(model.transform.GetChild(i).gameObject.GetComponent<Rigidbody>());
GameObject.Destroy(model.transform.GetChild(i).gameObject.GetComponent<BoxCollider>());
model.transform.GetChild(i).gameObject.AddComponent<MeshCollider>();
}
}
}
but when i run this script it gaves me this error
Actor::updateMassFromShapes: Compute mesh inertia tensor failed for one of the actor’s mesh shapes! Please change mesh geometry or supply a tensor manually!
UnityEngine.GameObject:AddComponent()
its caused by this line model.transform.GetChild(i).gameObject.AddComponent();
When i run my script without this line everything works fine … and when i attach a mesh collider in editor during runtime there is no problem.
Any help ?
Thanks