Ragdoll synchronization

Hi. I ran into such a problem that the ragdoll cannot be synchronized on the server. I made it so that when an NPC died, he would leave a ragdoll and players could drag it. But as it turned out, the server cannot do this, since there is no network identity on the NPC’s body. And my network identity is located on a capsule collider, which is located above the NPC model and this collider is responsible for movement, health conditions and the like. At first, I thought that it was possible to dynamically add network identity in the script, but this does not help. Here’s how, in theory, you can make it so that players can drag NPC models by any part of the body, or at least by the body, without a second network identity?

Is the original NPC a networked object? If so, I’d assume the ragdoll is still that same object albeit “dead”.

You will need to have that ragdoll body a network object one way or another. Also consider that you can’t (well, you can but you really shouldn’t) make that ragdoll a NetworkRigidbody. That would behave awkwardly and will be costly in terms of traffic. Instead, consider dragging a ragdoll is merely moving a NetworkTransform to another place without physics, and the ragdoll body simply follows that position around. You will have to accept that the body’s posture will be different for every client.

Yes, the NPC itself is a network object. My network identity is located on a capsule collider, and the NPC model itself is located in the hierarchy under the capsule. When an NPC dies, the capsule collider turns off, and the model’s animation turns off and it becomes a ragdoll. I can drag NPCs for the capsule itself, but I can’t for body parts, since the child objects don’t have a network identity and the server can’t synchronize the positions of the body on the server when dragging. I don’t know if it was possible to explain it clearly, but I want to understand how players can interact with NPC child objects, provided that the objects do not have an identity.

Not sure how you implement the dragging. It sounds like you may have some sort of way to synchronize the alive NPC with its NetworkObject position (probably through some controller script?) but that seems to stop working if the NPC is a dead ragdoll. I believe that Rigidbodies ignore the parenting hierarchy, which would explain why the ragdoll stays in place.

It sounds like all you need is to make the ragdoll update its position to that of the parent NetworkObject. For a simple test, activate a script on any of the ragdoll’s rigidbody bones which will update its position to that of the parent network object every FixedUpdate.

Sorting out how to make that movement smooth is another challenge but I think there will be “drag ragdoll” tutorials around. Most likely by using AddForce or a joint.