x


Are AnimationEvents Supported for Animations Imported from Max/Maya?

If I import an animation from Maya, it comes in as read-only and you can't use the Unity Editor to add Animation Events to it (yes you can "copy" the anim and add events to the copy, but that's a nightmare to maintain).

Is there any way to add AnimationEvents (or anything that could be interpreted similarly) from within Maya so that they appear on read-only animations?

Is there any way of programmatically adding AnimationEvents to imported animation (possibly via a script)?

more ▼

asked Nov 23 '11 at 12:39 PM

StuartHarrison gravatar image

StuartHarrison
1 2 2 2

I've added a Unity Feedback suggestion about this issue. If you're still having problems with it, you can vote for it here: http://feedback.unity3d.com/unity/all-categories/1/hot/active/adding-events-to-readonly-anim-

Jan 16 at 03:07 PM Rob Fireproof
(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

Sure, what you need is AnimationClip.AddEvent and AnimationEvent. But be careful, you add the event to the animationclip not to an instance of this clip. When you have two or more instances of your model you should add your events only ONCE because they are shared between all models that uses this animation.

You can maintain your own external solution like storing the events in a txt file and parse it at Start().

more ▼

answered Nov 23 '11 at 12:47 PM

Bunny83 gravatar image

Bunny83
46.8k 12 50 210

Option B then, ok - so is there any way to enumerate which events have already been added to an animation clip (so we can ensure there are no duplicate events)?

Nov 23 '11 at 02:18 PM StuartHarrison

Unfortunately not, they have to be added at runtime so you can't save it into the animation clip since the animation is stored with the imported model. Just add a script to a gameobject in your scene and add the events there.

Well, there is a way to automatically copy the AnimationClip with an AssetPostProcessor so it can be edited, but it's much more complicated and you have to take care of the re-import-case or your edits will be overwritten.

You can of course create an AssetPostProcessor that grabs the animation events from a config file and adds the events at import-time with AnimationUtility.SetAnimationEvents.

SetAnimationEvents will replace any existing events on that clip. Keep in mind that SetAnimationEvents is a function from the UnityEditor namespace and is not available at runtime.

Nov 23 '11 at 02:55 PM Bunny83

A common way for custom configs are text files which contains the required information. Something like:

AddEvent,AnimationName,Time,FunctionName,Parameter, ...
AddEvent,run,0.2,PlayFootstepSound,
AddEvent,attack,0.8,PlayAttackSound,

This is just an example. This file can be parsed inside the PostProcessor and add the events to the corresponding clip.

Nov 23 '11 at 03:01 PM Bunny83
(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:

x3922
x403
x46

asked: Nov 23 '11 at 12:39 PM

Seen: 1815 times

Last Updated: Jan 16 at 03:07 PM