have a rig for a veloceraptor with a bad model attached to it, so what i need is for the new model to be attached to the rig instead so it uses the same animations. I hope that makes sense.
Take a look at this script. I have used it to make a character “wear” a piece of clothing, but you can modify it to suit your own needs easily.
You new, improved model needs a rig with the exact same number of bones, but it needs no animations itself.
[Shared skeleton and animation state][1]
Also take a look at my own thread:
[Weightless bones don’t get added to SkinnedMeshRenderer bone array?!?][2]
I made some changes to it:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class test : MonoBehaviour {
public GameObject target;
public Transform rootBone;
//bones List gets all bones from the SkinnedMeshRenderer at Start()
public List<Transform> bones = new List<Transform>();
//boneArray Transform gets filled in the assign function. It has to have the same bones in it as the bones List, or there will be an error.
//If the main body mesh is missing any bones, try giving them weights or keyframes and export again.
public Transform[] boneArray;
void Start () {
}
void Update() {
if(Input.GetKey(KeyCode.M)) {
if(target != null) {
AssignToActor();
}
}
}
void AssignToActor() {
//parent object to actor just in case, and move it there (although the bone movement technically takes care of it)
transform.parent = target.transform;
transform.localPosition = Vector3.zero;
SkinnedMeshRenderer targetRenderer = target.GetComponent<SkinnedMeshRenderer>();
Dictionary<string, Transform> boneMap = new Dictionary<string, Transform>();
foreach(Transform bone in targetRenderer.bones) {
boneMap[bone.name] = bone;
}
SkinnedMeshRenderer thisRenderer = GetComponent<SkinnedMeshRenderer>();
boneArray = thisRenderer.bones;
for(int i = 0; i < boneArray.Length; i++) {
string boneName = boneArray*.name;*
_ if(boneMap.TryGetValue(boneName, out boneArray*) == false) {_
_ Debug.LogError("failed to get bone: " + boneName);_
_ Debug.LogError(i);_
_ }_
_ }_
_ thisRenderer.bones = boneArray; //take effect*_
* }*
}
_[1]: http://answers.unity3d.com/questions/44355/shared-skeleton-and-animation-state.html*_
_[2]: http://answers.unity3d.com/questions/668332/weightless-bones-dont-get-added-to-skinnedmeshrend.html*_