- Home /
Creating new rigged clothing for existing character prefab
I've got a character prefab which has a model using multiple meshes rigged to the same skeleton. This all works great with the clothing that was on the character when I first imported it to Unity.
I tried to create a new piece of clothing and add it to the blend file in Unity, this works, but the character prefab doesn't get the new piece of clothing automatically (which makes sense).
I tried to manually copy the mesh from the blend file into the existing prefab but this doesn't seem possible.
I dragged the blend file into the scene, copied the clothing object to the prefab object in the scene, assigned the root bone to the existing skeleton, but the new clothing does not animate with the existing clothing.
It all works fine for the blend file if I drag in a fresh copy, but I only want to add the new object.
I don't want to have to recreate the prefab every time I add a new piece of clothing, because it's got all sorts of scripts and colliders attached to the skeleton.
Has anyone experienced this before?
Thanks!
Answer by Serinx · Sep 20, 2018 at 07:00 AM
Found the solution, I wrote a script which sets the skinned mesh renderer bones of the clothing to the bones of the main character and it all went smoothly. If anyone else has this issue, just attach the following script to your clothing item and set the Target Skin to your main character mesh object (the one with the working skinned mesh renderer component).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class BoneRetarget : MonoBehaviour {
[SerializeField] SkinnedMeshRenderer targetSkin;
// Use this for initialization
void Start () {
SkinnedMeshRenderer mySkin = GetComponent<SkinnedMeshRenderer>();
mySkin.bones = targetSkin.bones;
}
// Update is called once per frame
void Update () {
}
}
Your answer
Follow this Question
Related Questions
Copy the state of one animator to another 0 Answers
Trouble replacing a mesh on a pre-existing model 0 Answers
Creating Avatar 1 Answer
Animation resetting to the muscle pose 0 Answers
I can preview the animation but in scene it doesn't work 0 Answers