- Modifié
Performant Reusable Ragdolls
Our game keeps a pool of character ragdolls so we can have multiple copies of the 'dead' player persist in the game world. (Players die often, and it's a 6 player game)
Basically I have a Prefab apart from my actual playable character prefab that has a SkeletonRagdoll component on it and I call Apply() to activate the ragdoll, and later Reset() to clean it up. This is all working well..... but it is not very performant to be calling Apply() every death of the player as it has to run through every bone, call AddComponent a ton of times (Rigidbodies, Hinge Joints, etc).
With all that said, I'm trying to find a way that I can setup the Ragdoll just 1 time at game start and be able to reuse the ragdolls without needing to call Reset() and later Apply(). The issue is that I'm not sure how to approach "restoring" the ragdoll to a state that it will be ready to be used again for the next player death without using the existing Reset() method. I'd like to be able to simply move the ragdoll to a player death position, and apply a velocity to send it flying. (all the child rigidbodies of the ragdoll make this complicated)
I'm optimizing the game for Nintendo Switch and am seeing hiccups in performance when the ragdoll's Apply() method is run, so I'm trying to find a way around this.
Does anyone have any advice?
Unfortunately your observations are correct that the SkeletonRagdoll
and SkeletonRagdoll2D
example components are not optimized in this regard.
The best solution here would most likely be to modify the SkeletonRagdoll
or SkeletonRagdoll2D
example component (or best create your own new class) to generate all Rigidbody
elements at the start, but have them deactivated (set to kinematic=true
or simulate=false
). The mix
value would also be set to 0
. Then Apply()
should set the Rigidbody
locations to the current bone position and activate the Rigidbody
components (kinematic=false
or simulate=true
). The mix
value would then be set to 1
or fade in as usual. Plus as you said, an impact force should be applied to e.g. the main rigidbody to make it feel affected by the shot.
Since we are currently working on some high priority tasks on the spine-unity
runtime, I can currently only offer the above text description of a potential solution. Is this sufficient for you for now? If not, we can later implement the functionality above in the official SkeletonRagdoll
or SkeletonRagdoll2D
example components, but it will take us some time until we get to this task.
Thank you for the recommendations Harald.
I'll make an attempt to create my own class following the setup you recommended. I'll be sure to post if I'm successful
Great to hear, all the best with the implementation!