|
|
|
| View previous topic :: View next topic |
Spacemonkey
Joined: 24 Oct 2008 Posts: 89
|
Posted: Wed Mar 18, 2009 10:50 am Post subject: 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:
| 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 |
|
|
mklaurence

Joined: 26 Dec 2008 Posts: 98 Location: Chicago, IL
|
Posted: Tue Mar 24, 2009 5:06 am Post subject: |
|
|
|
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 |
|
|
Spacemonkey
Joined: 24 Oct 2008 Posts: 89
|
Posted: Thu Apr 02, 2009 1:01 pm Post subject: |
|
|
|
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 |
|
|
duke

Joined: 10 Jan 2007 Posts: 191 Location: Melbourne, Australia
|
Posted: Tue Apr 07, 2009 7:05 am Post subject: |
|
|
|
| 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 |
|
|
Spacemonkey
Joined: 24 Oct 2008 Posts: 89
|
Posted: Wed Apr 08, 2009 11:58 am Post subject: |
|
|
|
Thanks!  |
|
| Back to top |
|
|
|
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
|
|
|
|
|
|