x


Creating and scripting a prefab with multiple animation clips

I'm trying to emulate the behavior of the heron in the island demo. That prefab has underneath it an animation node, HeronAnimated, which in turn has a list of animation clips. This note has an icon identical to the prefab one, but one level below in the hierarchy.

When I create an empty prefab and then try to drag animation clips into it, only the first works. The second time I try to drag in a clip, I get a warning dialog about a "possible unwanted prefab replacement" Also, I cannot seem to create a new "animation" (Assets->Create->Animation interface actually creates an animation clip at top level, not an animation node under the prefab).

I can manually add animation clips to the prefab animation object in the inspector by upping the size count and then pointing to other animation clips.

However, when I try from script to reference any of the animations, I get a null reference exception.

I am new to Unity. I have tried both the character and scripting tutorials to no avail...

more ▼

asked Nov 24 '09 at 03:46 AM

Tereza Flaxman gravatar image

Tereza Flaxman
11 1 1 2

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Your GameObject should have 1 Animation component on it and in the Animations array (through Inspector) you add all the animations you need to use.

In the code you activate the animations using the name shown in the inspector (case sensitive). So for example if you have an animation Run you can activate it with something like:

animation.CrossFade("Run");

more ▼

answered Nov 24 '09 at 07:11 AM

Jaap Kreijkamp gravatar image

Jaap Kreijkamp
6.4k 20 26 70

Thanks, Jaap

I think what I was missing was that my script was attached to the wrong place in the hierarchy - the root node of the rigging - instead of the top level of the prefab. Animation is now working. All I need now is to get translation working. "transform.Translate" on a script at the character level isn't moving the character.

Nov 24 '09 at 03:44 PM Tereza Flaxman

My experience is that animation can mess up movement, as part of the animations are movements. The solution is to have the node with animated mesh placed in another gamenode and move this parent gamenode instead of the gamenode with animated mesh.

Nov 24 '09 at 10:37 PM Jaap Kreijkamp
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3776
x1043

asked: Nov 24 '09 at 03:46 AM

Seen: 3308 times

Last Updated: Nov 24 '09 at 03:46 AM