Adding Animation Events on Imported Clips

Do I understand that correctly?
The documentation says Animation Events can be added for imported clips by

  1. scrubbing through the animation via the preview
  2. adding via events in the import settings above (see image)

BUT if I want to set the events precisely in the timeline I cannot drag the animation events.


It’s only possible to do so in the import settings (which is super imprecise).

Unity aswers has a solution by copy/pasting the animation into a Unity native animation clip but that can’t be the solution. This makes updating the animation impossible.

Am I missing something here?
Is this really the only way to do this?

Hi there,
I’ve successfully got animation events importing on the FBX assets using an AssetPostProcess, during the PreProcessModel step.

If you are defining your clip animations during this step using ModelImporterClipAnimation objects, you can assign an array of AnimationEvent objects to the events property of each of your ModelImporterClipAnimation clips.

So my basic flow is:

  • Build dictionary of events, mapped to the target clip names.
  • Build array of ModelImporterClipAnimation objects.
  • For each ModelImporterClipAnimation object, check if the event dictionary has an entry by that name, and assign it’s event array to the clip if it matches.

In previous versions of Unity I had this half way working utilising serialized data modification during the PostProcessModel method, but although the event appeared in the editor, it never fired in game. Utilizing the PreProcessModel method above allows the event to reliably fire as expected.

(Unity version 2018.1.8f1)

2 Likes

Hi There! I take it as though your animations are (read only) which prevents you from adding the events directly in the animation panel? Well, this is how I do it:

  1. Select the animation file in your imported animation fbx or what-so-ever.
  2. Press Ctrl-D to duplicate
  3. Walah, its no longer read only and you can freely add events and what-not to your animations.

Hope this helps!

Unity Version 2019.3.5f1
October 10, 2020

1 Like

Could I ask you to post what this looks like in code, and also a screenshot of what the result is in editor?
I’m having a hard time understanding the application of this. I can’t tell the difference between this process and copy and pasting the animation clip in order to edit the timing of events, not to mention activating and deactivating gameobjects in the hierarchy.