Sharing animation clips between models

 
Post new topic   Reply to topic    Unity Community Index // Scripting
View previous topic :: View next topic  
Author Message
Spacemonkey



Joined: 24 Oct 2008
Posts: 89

PostPosted: Wed Mar 18, 2009 10:50 am    Post subject: Sharing animation clips between models Reply with quote
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:
Code:

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:
Code:


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?
Back to top
View user's profile Send private message
mklaurence



Joined: 26 Dec 2008
Posts: 98
Location: Chicago, IL

PostPosted: Tue Mar 24, 2009 5:06 am    Post subject: Reply with quote
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:
Code:

AnimationClip clip = (AnimationClip) ((GameObject) Resources.Load("Characters/Animations/" + clipName)).animation.clip;
character.animation.AddClip(clip, clipName);
character.animation.Play(clipName);
Back to top
View user's profile Send private message
Spacemonkey



Joined: 24 Oct 2008
Posts: 89

PostPosted: Thu Apr 02, 2009 1:01 pm    Post subject: Reply with quote
Thanks a lot:D 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.
Back to top
View user's profile Send private message
duke



Joined: 10 Jan 2007
Posts: 191
Location: Melbourne, Australia

PostPosted: Tue Apr 07, 2009 7:05 am    Post subject: Reply with quote
Spacemonkey wrote:
Thanks a lot:D 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.
Back to top
View user's profile Send private message
Spacemonkey



Joined: 24 Oct 2008
Posts: 89

PostPosted: Wed Apr 08, 2009 11:58 am    Post subject: Reply with quote
Thanks! Smile
Back to top
View user's profile Send private message
Post new topic   Reply to topic    Unity Community Index // Scripting All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum