- Home /
Trying to add a mesh parented to an armature to another instance of the same armature
So I have my base model/rig, and from that model I created prefabs which are basically copies of the original with different clothes toggled on or off.
I just added a new hair-mesh to the base model/rig. I want to add this new hair mesh to some of my prefabs, so what I did was
1) drag a whole new copy of the original rig, LowPolyModel, into the prefab, Cashier
2) right clicked and unpacked the new copy of LowPolyModel completely
3) pulled over the two new hair meshes from LowPolyModel onto Cashier, updated the root bone to use the root bone of Cashier and then deleted copied instance of LowPolyModel from the prefab
After step three, the hair meshes disappear. The game objects are there, but the meshes are invisible. I suspect that these game objects or the skinned mesh renderer is still referencing something from the now deleted LowPolyModel instance.
It also seems like I can't add the mesh manually with a new gameobject/skinned mesh renderer. There's another step that I'm either missing or isn't in the inspector.
Does anyone know how I can go about doing this? I rather not have to re-do my entire prefab every time I add new hair or clothes.
Thank you.
Answer by jfonz001 · Aug 02, 2021 at 08:20 PM
Got it:
https://answers.unity.com/questions/1442963/how-to-re-apply-a-mesh-to-an-armature.html
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class ReassignBoneWeigthsToNewMesh : MonoBehaviour
{
public Transform newArmature;
public string rootBoneName = "Hips";
public bool PressToReassign;
void Update()
{
if (PressToReassign)
Reassign();
PressToReassign = false;
}
// [ContextMenu("Reassign Bones")]
public void Reassign()
{
if (newArmature == null) {
Debug.Log("No new armature assigned");
return;
}
if (newArmature.Find(rootBoneName) == null) {
Debug.Log("Root bone not found");
return;
}
Debug.Log("Reassingning bones");
SkinnedMeshRenderer rend = gameObject.GetComponent<SkinnedMeshRenderer>();
Transform[] bones = rend.bones;
rend.rootBone = newArmature.Find(rootBoneName);
Transform[] children = newArmature.GetComponentsInChildren<Transform>();
for (int i = 0; i < bones.Length; i++)
for (int a = 0; a < children.Length; a++)
if (bones[i].name == children[a].name) {
bones[i] = children[a];
break;
}
rend.bones = bones;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613041123im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Importing .blend file - Missing Animation 1 Answer
Mesh is flipped thanks to bone but armature is working 0 Answers
Importing from my blender to unity with armatures causes my mesh to be see through 0 Answers
My animation will not play after I apply armature in Blender. 1 Answer
Importing a mesh with multiple armatures from blender 1 Answer