- Home /
How to put t-shirt on animated avatar
Hi everyone,
My question is how to attach t-shirt mesh to my avatar. I have found a similar topic:
But I am not able to get it working. Code that I am using I present below.
using System.Collections.Generic;
using UnityEngine;
public class Equipmentizer : MonoBehaviour
{
public SkinnedMeshRenderer TargetMeshRenderer;
void Start()
{
Dictionary<string, Transform> boneMap = new Dictionary<string, Transform>();
foreach (Transform bone in TargetMeshRenderer.bones)
boneMap[bone.gameObject.name] = bone;
SkinnedMeshRenderer myRenderer = gameObject.GetComponent<SkinnedMeshRenderer>();
Transform[] newBones = new Transform[myRenderer.bones.Length];
for (int i = 0; i < myRenderer.bones.Length; ++i)
{
GameObject bone = myRenderer.bones[i].gameObject;
if (!boneMap.TryGetValue(bone.name, out newBones[i]))
{
Debug.Log("Unable to map bone \"" + bone.name + "\" to target skeleton.");
break;
}
}
myRenderer.bones = newBones;
}
}
When I was checking it looks like my myRenderer.bones.Length = 0, as a target I connected my main character, and script is called on the t-shirt. Does my t-shirt mesh needs to have bones also? How can I create them on it?
I attach link to google drive with pictures what I mean, because I was not able to upload them here.
Thanks in advance.
Your answer
Follow this Question
Related Questions
Skinned meshes from separate files sharing the same skeleton instance 1 Answer
Copy the exact "state" of an Animator / RuntimeAnimatorControler to another Object 0 Answers
Bones in a different order within SkinnedMeshRenderer 1 Answer
Creating new rigged clothing for existing character prefab 1 Answer
Can the animation editor create local rotational data? 3 Answers