How do I adjust the vertices of a skinned mesh seamlessly?

I’m currently working on an avatar editor for a game. The Avatar Editor has sets of controls which allow me to manually tweak the vertices of a skinned “Male Base Mesh”. The code all generally works properly up until the point where I adjust the actual vertices of the Skinned Mesh. Once this happens, the mesh no longer orients properly to the rig.

The code I’m using to update the mesh is as follows:

    private void UpdateMesh()
    {
        Mesh mesh = new Mesh();//This is the new mesh we'll make changes to
        SkinnedMeshRenderer sceneMeshRenderer = spawnedPrefab.transform.Find("Avatar_Male_Body_Geo").GetComponent<SkinnedMeshRenderer>();

        sceneMeshRenderer.sharedMesh = selectedData.baseMesh;//Assign the base Mesh to the skinnedmeshRenderer
        sceneMeshRenderer.BakeMesh(mesh);//Bake the mesh's data into our new mesh

        Vector3[] vertices = mesh.vertices;

        for (int ix = 0; ix < bodySliders.Count; ix++)
        {//once we get here, go through all the vertices in the mesh and update their positions based on the controls
            for (int i = 0; i < vertices.Length; i++)
            {//This is where all the changes are made to the vertices
                vertices _+= bodySliders[ix].control.position.cur * bodySliders[ix].control.weightTable*.weight;*_

}
}

mesh.vertices = vertices;//Assign the new vertex positions
sceneMeshRenderer.sharedMesh = mesh;//Reassign the mesh
}
As you can see from the following image, after this code executes, the mesh is no longer properly oriented to the rig and I don’t know why. The mesh still animates properly and the changed vertices are even updated properly on the mesh. It seems to be the mesh itself is just changing orientation for some unclear reason.
[72740-adjusting-skinned-mesh.png|72740]_
I’m sure the answer is something simple, but I don’t know what it is.
_

If your mesh script is attached to another gameObject that is a child of another, the mesh object may be orienting itself to its parent orientation. In order to fix this (if this parenting is the case) you have to remove the mesh object, reset the transform of the rig, add the mesh object, THEN rotate your rig object to its proper orientation. I dealt with this problem with weapons and instantiating them into a hand instead of attaching them before animation and just disabling them. It’s a pain, but that’s just the way Unity works.