So i have a model with joints and when it hits the ground i want it to go through and delete all the rigidbodies and also from what i find out the character joint as well so that there is less physics to create. what i have is a script like this. These are Ragdoll dead bots.
function DestroyRigid(){
Destroy(GetComponent(CharacterJoint));
Destory(rigidbody);
// call on the children objects of this object within dead bot.
BroadcastMessage(DestroyRigid);
}
well now it seems that it freezes unity. does anyone know of a command to just delete all the rigidbodies of all the children, and keep in mind that these children have children that have children and so on as the joints are connected. Thanks ahead of time.
You are calling DestroyRigid recursively within DestroyRigid with the BroadcastMessage call. You just need to remove the BroadcastMessage from the function and call it once from whatever function activates the destruction.
ok well i got rid of the broadcast message but it still only deletes the rigidbody from the main section of the body it doesn’t do it in any of the children
in the file image you can see the hiearchy, different components like spine 3, arms, elbows, hips, knees, and ankles all have the “characterJoint” component, and the “rigidbody”, now i can’t remove a rigidbody without removing the character joint first, i have the destroy script attached to each object that has these but it seems like they aren’t getting the broadcastmessage i am sending out. any suggestions?
to me it seems like broadcastmessage only sends it to the children, but then it doesn’t go past them when i would think it should go to the children of the children and so on down the line.
You need to call a function like the following on the root object:-
function RemoveRigidbodyRecursively(obj: Transform) {
if (rigidbody) {
Destroy(rigidbody);
}
for (child in obj) {
RemoveRigidbodyRecursively(child);
}
}