How to handle dead bodies? | 'Freezing' ragdolls for performance?

My enemies turn into ragdolls after dying. After slaying more and more of them, battlefield is scattered with ragdoll bodies that are constantly simulating physics. I guess it’s bad for performance? :wink:
I would like to optimize it by disabling physics simulation after like ~10 seconds from death. But when I simply call “Set Simulate Physics” function on a skeletal mesh, it goes back into T-Pose.
Is it possible to ‘freeze’ current ragdoll pose and prevent it from simulating physics?

Edit: Woah. Just realized. This title.
;D

2 Likes

Any clues? I saw something like this in a few games, enemy ragdolls were active for ~10 seconds and then their physics simulation turned off.
But in UE, I still can’t figure out how to keep ragdolls in current pose, instead of reverting them back to T-Pose.

You could do this with a PoseableMesh component.
Clone the socket transforms to it, then hide and disable physics on the main mesh.

3 Likes

I think there is a node called PutAllRigidBodiesToSleep. I think that is what I’m using to freeze the ragdoll. I also have to turn off certain collisions so other players can’t start kicking the frozen ragdoll, although it is pretty hilarious to see.

I would put more details into this but I’m at work. If you haven’t figured it out by the time I get home, I’ll post the nodes I use for the death sequence.

This PoseableMesh component trick works like a charm :slight_smile:
Thanks guys!

Hey Slavq where did you put this blueprint? inside the enemy or level?

I don’t remember 100%, but probably inside enemy class, in a custom ‘FreezeRagdoll’ function. So the ‘Mesh’ node is your enemy skeletal mesh. Then every time you need to freeze a ragdoll on an enemy, you call the ‘FreezeRagdoll’ function on it and it works.

okay it is on enemy. I got the idea.

Sorry for the necro, but I tried out this technique and it seems to work pretty well, except that when the meshes get swapped out I start seeing this weird blur on the bodies. It looks like it might be motion blur, but I’m not positive. Has anyone seen this or have any ideas what could be causing it / how to fix it?

yeah … I am seeing this aswell in 4.21… been trying to fix it for a few a hours, no solution yet.

so I have a workaround … instead of creating a poseable mesh I do this in my enemy BP … save pose snapshot > set bool variable(freeze) > set all bodies simulate physics(off). Then in my animation BP just pass in the freeze bloolean and use that to change my state. Inside the state just use a pose snapshot with the same name as set in my enemy BP. Not sure how efficient but seems to work fine.

1 Like

That solution fits for me. Thank you very much!

This sounds like a really clever approach, craigBeads. Could you post a screenshot of your blueprint setup?

So this is the solution I went with. It’s just a single line of code, just add a


GetMesh()->PutAllRigidBodiesToSleep();
 

and it freezes the ragdoll.

But this is just so easy and the other solutions posted after this in this thread are so overly-complicated that I’m thinking maybe putting them to sleep isn’t enough? I assume when you put them to sleep they completely stop all physics queries so it has zero performance impact from physics, so it would be just as good for performance as the other solutions here, right? Or am I missing something?

In 2020 you are probably better off creating a Dead animation state, taking a snapshot pose of the mesh when it’s finished bouncing around (which should be implemented manually during the “ragdoll” state), and putting the mesh in that state.

I’m not 100% done with my system or I’d share some more details about it, but suffice it to say, that you can use physical animations instead of simulating physics without any control of the rigidness of the different bodies.

Another thing to note, to prevent the meshes from spazzing out I ended up scaling the tensor from the extremities inwards with X values of 5,4,3,2.
You and anyone else can mostly follow the live training for it.https://youtube.com/watch?v=N1tDjbFXeOo
There are a few gotchas that you may come across, but anything is better then leaving the actor in a ragdoll state, performance wise…

This setup worked for me, I’m using the third person character template in 4.24:


8 Likes

I also had a issue that after the dead anim the skeleton goes back in Tpose…I solved like this:
get last frame of your dead animation, create a new animation from it with just 1 frame (it will have the body dead on floor), then play that anim after the dead animation and tag Loop to True. In this way the skeleton will die, play the dead animation, then if needed put a delay N sec (N=dead anim length) and when done, play the new anim in a loop.

Similar solution except no need to name a snapshot - so if the final pose changes, it should still work well.

The Anim Graph has a “Copy Pose From Mesh” function.

4 Likes

I tried the first method, with named snapshot and while it works, there is a massive jolt happens to the mesh when taking pose snapshot :frowning: So it’s basically unusable due to that. Any idea why and how to eliminate that jolt ?

I haven’t tried second method because it’s not going through fast path.

I solved this by setting the true and false blend time to 0 instead of 0.1
Are you the one from skinned decal discord? :smiley:

3 Likes