How do you set the positions of a ragdoll to that of bones in the last frame of played animation?

Hello, I have encountered a problem with my ragdolls in unity. The way I am doing ragdolls is prefabbing them and instantiated them when the main game object is killed.

They instantiate just fine but I am having trouble setting the positions of the bones to that of the animation at time of death.

Here is what I am doing:

GameObject ragdoll = Instantiate(m_ragdoll, transform.position, transform.rotation) as GameObject;
Utilities.ConfigureRagdollPosition(transform, ragdoll.transform);

ConfigureRagdollPosition():

public static void ConfigureRagdollPosition(Transform reference, Transform ragdollPart)
{
	ragdollPart.localPosition = reference.localPosition;
	ragdollPart.localRotation = reference.localRotation;

	for (int i = 0; i < reference.childCount; i++) 
	{
		Transform ref_t = reference.GetChild(i);
		Transform rag_t = reference.GetChild(i);

		if(ref_t != null && rag_t != null)
			ConfigureRagdollPosition(ref_t, rag_t);
	}
}

The ragdoll just starts up in the T pose, because I’m assuming that animations don’t work the way I thought they did (i.e. moving the game objects with the bones).

What is the correct way of doing this?

Additional Info:
I am currently working with the unity construction worker model and animations for this.
Debug.Log shows that it is iterating through the children recursively.

It seems to me that on line 8. and 9. of that script that you are setting the reference and the ragdoll to be the same transform and therefore will be setting the local position and rotation to be the same as it is. On line 9. you probably want to use the ragdollPart instead (assuming it has the same number of bones and the bones are named the same).

Other than that this is a great way of setting the position of bones for a ragdoll and animations do work by moving/translating the bones of gameObjects.