[Solved] Adding Skinned Mesh Rendered Component

I’ve been working on a quick save/load system for a project and almost everything seems to be going smoothly.
During the loading, I’ve managed to load most components perfectly. However, there are some issues I’ve had with the skinned mesh renderer.
-Note that a model is composed of multiple pieces.
-Also note that the player model has been put in the scene beforehand, and that’s why is looks normal
This is an example of the issue:


Here’s the script for loading the skinned mesh:

                SkinnedMeshRenderer fil = (SkinnedMeshRenderer)compo.com;
                fil.sharedMesh = theMesh;
                fil.material = theMaterial;
                if (gms.ContainsKey(theGameObjectID))
                {
                    // gm is the gameObject, gms is a dictionary that keeps track of the IDs
                    Helper.SetSkeletonBase(obj, gms[theGameObjectID].gm.transform);
                }
                else {
                    Debug.Log("Did not find root bone");
                }

And for the skeleton code:

    public static void SetSkeletonBase(GameObject me, Transform rootBone)
    {
        SkinnedMeshRenderer BonedObject;
        BonedObject = me.GetComponent<SkinnedMeshRenderer>();
        me.transform.localEulerAngles -= rootBone.eulerAngles;
        BonedObject.rootBone = rootBone;
    }

I’ve been struggling with this issue for a while and I’m out of ideas .-.

Thanks in advance ^^

Hello,

I never tried to instantiate a SkinnedMeshRenderer, in my project i load a default character GameObject and i swap mesh inside (with characters using the same rig). But that way seems cool 2.
Meshes insides your objects seems to have incorrect Transform values. In order to make a test, maybe you can note Transform values for meshes in your gameObject (corpse,head,hear). And set them back when you spawn your object, something like

  corpse.transform.localPosition = new Vector3(0.02929915f, 0.2750888f, -0.01536892f);
  corpse.transform.localRotation = new Quaternion(0.3638686f, 0.5793739f, -0.6536294f, 0.3235648f);

(you need to switch editor in debug bug to get full Quaternion values)

I guess that’s a bit uggly, but you can check if your character works. And think to a clever solution after.

Nah, this didn’t work :confused:
I did have the transform values set correctly already, but I also tried resetting them from the SetSkeletonBase function, but still the same issue :confused:

So it seems like I had to add the exact bone transforms to each skinned mesh, so I had to save each single bone into the save file. Anyway, I hope that helps someone in the future