|
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)?
(comments are locked)
|
|
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(). 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: 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)
|

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-