For characters customization I using the simple script:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ClothesSimpleScript : MonoBehaviour {
public GameObject m_attached;
void Start () {
SkinnedMeshRenderer targetRenderer = m_attached.GetComponent<SkinnedMeshRenderer>();
Dictionary<string, Transform> boneMap = new Dictionary<string, Transform>();
foreach( Transform bone in targetRenderer.bones )
{
boneMap[bone.name] = bone;
}
SkinnedMeshRenderer thisRenderer = GetComponent<SkinnedMeshRenderer>();
Transform[] boneArray = thisRenderer.bones;
for(int idx = 0; idx < boneArray.Length; ++idx )
{
string boneName = boneArray[idx].name;
if( false == boneMap.TryGetValue(boneName, out boneArray[idx]) )
{
Debug.LogError("failed to get bone: " + boneName);
Debug.Break();
}
}
thisRenderer.bones = boneArray; //take effect
}
}
Nothing is satisfactory until I came to the import into the project of the clothing that belongs to the legs, ie trousers, pants and so on. They adding to the body of the character buggy. Right leg terribly twisted. Everything else works. Jackets, shirts, etc. also work without problems.
Here pants, standing by themselves (not added to the body of the character):
But the pants in the game, has added to body using script (disabled visibility of the character body, to better see the pants). As you can see, right leg twisted:
What’s the matter?! I verifies the correctness of the names of all the bones, thought, where can the letter accidentally added a letter - in pants and torso completely identical skeletons! At the same time a female character that’s all right, bug happening only with men’s clothes (weird, huh?). Pick up the script buggy Men’s pants and drop this on a woman’s body (skeletons of the all characters is identical) - the same problem! Pants twists on female and the male bodys equally. If I do not use a script, and add pants on scene, add them animator controller, they will normally run, jump, without bugs. It is necessary to apply script - again there is a bug (with any feet-clothing: pants, shorts, etc) … What do you think?
P.S. Link to my project- https://yadi.sk/d/FhZ0SXNBsjjHM