Sharing animation clips between models

Hello,

I’m having trouble assigning the animations from one imported fbx file to another. They both have the same amount of bones and naming conventions and setting the animation clip of object A in the editor to active on object B works fine. That is, object B now loops through the animation stored in object A. But what I really need is to be able to do this in script. I tried to add the Model’s clips from the default clip of Skeleton like so:

function Awake()
{
	Model = transform.Find("P2_Lab");
	Skeleton = transform.Find("P2_Skl");
}

function Start()
{

Model.animation.AddClip(Skeleton.animation["Take 001"].clip, "walk1", 3, 4,true);
Model.animation.AddClip(Skeleton.animation["Take 001"].clip, "walk2", 5, 6,true);

etc..

}

That didn’t work so I tried using GetComponent() instead:

var SklAnimation : Animation;

function Awake()
{
	Model = transform.Find("P2_Lab");
	Skeleton = transform.Find("P2_Skl");
}

function Start()
{
	SklAnimation = Skeleton.GetComponent(animation);

Model.animation.AddClip(SklAnimation.clip, "bindpose", 0, 1,true);
Model.animation.AddClip(SklAnimation.clip, "idle", 2, 3,true);

And that failed too… Any suggestions on how to make this work?

I’ve just started experimenting with animation sharing, and I’ve gotten some things to work well enough. Are you still having this problem? Have you tried playing the animation after you’ve added it? (it won’t play on its own).

You may also try exporting the animations separately - that’s what I’ve been doing. Basically, I export my mesh/biped FBX as the model, and export each animation (just a biped with animation keyframes) as a separate FBX. Then, I uses Resources.Load to get the animation and assign it:

AnimationClip clip = (AnimationClip) ((GameObject) Resources.Load("Characters/Animations/" + clipName)).animation.clip;
character.animation.AddClip(clip, clipName);
character.animation.Play(clipName);

Thanks a lot:smile: Didn’t spot your reply before now.

Trying it out now but I’m still a beginner when it comes to scripting so… get some error msgs I’m not sure how to solve. What I’m confused about are AnimationClip and Clip, are they classes or variables or what? If they’re classes then do I need to replace “AnimationClip clip” in the first line with something like this: “transform.AnimationClip clip” to make it work? Probably a very basic thing it’s just that the docs are extremely bare-bones when it comes to explaining the syntax of some of these terms.

AnimationClip is a type, like Terrain, GameObject, etc. The variable is clip, so you’d want to go clip.whatever.

Thanks! :slight_smile: