Skinned Mesh bug while assigning new bones
Hello. I've made a shirt for my character which is basically the same vertices as in the character model but without the unnecessary faces (like legs, head, etc.) - it has the identical rig, weights setup and it's in .blend format.
Now I put it inside of my player model, positioned it and applied a script that assigns it the bones of my character so it animates along with it but the thing is that it gets all messed up.
.
This is how it looks like in pause mode:
.
And this is what happens in play mode:
.
Here's how I setup the new bones:
public class BoneReplacer : MonoBehaviour
{
public GameObject target;
SkinnedMeshRenderer myRenderer;
Transform[] newBones;
SkinnedMeshRenderer targetRenderer;
Dictionary<string, Transform> boneMap = new Dictionary<string, Transform>();
void Start()
{
targetRenderer = target.GetComponent<SkinnedMeshRenderer>();
foreach(Transform bone in targetRenderer.bones)
{
boneMap[bone.gameObject.name] = bone;
}
myRenderer = gameObject.GetComponent<SkinnedMeshRenderer>();
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;
}
}
.
Generally everything is animating fine, bones are following the animation just right but as you can see the mesh is a mess. Does anyone of you know of any solution to this problem? I'd be very grateful for one!
Your answer
Follow this Question
Related Questions
Horizontal BlendTree Animations Not Working 0 Answers
is it possible to convert generic animations to humanoid ones? 1 Answer
Animation Issues, please help! 0 Answers
how can i detect GetBoneTransform(HumanBodyBones) is null or not null? 0 Answers
How to call 'Animator.Play' without wait for FixedUpdate? 0 Answers