Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Setting animation events in AssetPostprocessor

Discussion in 'Scripting' started by NoiseFloorDev, Jul 30, 2017.

  1. NoiseFloorDev


    May 13, 2017
    I'm trying to import animation events from metadata using AssetPostprocessor, by reading a JSON file alongside the FBX and adding them to

    If I do this in OnPreprocessModel, events aren't imported on initial import. Both clipAnimations and defaultClipAnimations are always empty. I think OnPreprocessModel happens before the FBX file is even read, so there's just no data. However, it does work the second time (if the FBX changes or I manually hit reimport).

    If I do it in OnPostprocessModel, events are saved and visible in the inspector, but the old data is still used if I play the scene. If I import a second time, the previous import's events are now used (and any changes this time aren't). Doing some binary searching in my project, I see that the data in Library lags behind by one import. It looks like Unity is updating the asset database, then running OnPostprocessModel, and the changes made in OnPostprocessModel are only updated to the asset database the next time. (However, this does work the first time.)

    So, I have to run my event importing in both OnPostprocessModel (so the initial import works) and also in OnPreprocessModel (so subsequent imports work). I tried calling EditorUtility.SetDirty, but I don't think that's applicable here.

    It's a quick process, so this doesn't hurt anything, but it's strange and I'm not sure if my workaround is reliable (having imports sometimes not take effect could cause headaches down the line). Anyone else seen this?