Search Unity

Re-import / reset animation

Discussion in 'Animation' started by joebain, Dec 4, 2017.

  1. joebain

    joebain

    Joined:
    Oct 24, 2014
    Posts:
    49
    Hi,

    I'm working on a project which uses lots of animations in binary fbx format. I've just received an updated file from the animator and the time range of the clip is different from the old one, so when I look at the fbx in Unity it shows a message "Clip range outside source take" I can manually change the start and end, but it would be nice to re-read the timings from the fbx to make sure I get the right values. I can't find a way to get unity to completely re-import the animation though. I have tried clicking "reset" in the context menu on the import panel, I have tried right clicking on the file in the project panel and clicking "Reimport", I have even tried deleting the .meta file for the animation and shockingly that doesn't work either. The (custom) name for the animation persists, along with the timings even if I delete the meta file!

    Does anyone know where unity is storing the animation import settings? Is this written back to the fbx maybe or stored in the application settings somewhere?

    Thanks

    Joe
     
  2. itchyOwl

    itchyOwl

    Joined:
    Feb 28, 2013
    Posts:
    25
    I was having a similar issue, which was not present in previous Unity versions (pre 2017.2).

    In short:
    You can either write a custom editor code to reimport the file or you can delete both the .meta file and the corresponding metadata in the Library/metadata/ folder.

    Longer version:
    In my project, I'm using a single file to import all the animations and when the animations change or I make more animations, I just reimport this file. I'm pretty sure that it used to work just by replacing the old file with a new, deleting the .meta file, and reimporting the asset. Not anymore: the new clips are not imported (or visible in the .meta file).

    Fortunately, I've made a tool to automate the animation processing, where I can choose to load the default clip animations or use the importer animations that are defined when the asset is imported first time. Reimporting the default clips in code works: the new clips are loaded and visible. So, I suspect that they changed the behaviour of reloading assets via the editor. I'm now using 2017.2, and I'm quite sure that it worked in 2017.1.

    The code to reimport the animation clips looks like this:

    Code (CSharp):
    1. var path = AssetDatabase.GetAssetPath(asset.GetInstanceID());
    2. var importer = AssetImporter.GetAtPath(path) as ModelImporter;
    3. var clips = loadOriginalClips ? importer.defaultClipAnimations : importer.clipAnimations;    // This is the key line
    4. importer.clipAnimations = clips;
    5. AssetDatabase.ImportAsset(path);
    6. AssetDatabase.SaveAssets();
    This code can be run either in a custom asset importer class or in some other editor script.

    Regarding the question where the animation import settings are stored, the answer seems to be: in both .meta file and in the metadata library. The official tutorial on assets and object serialization tells us that the results of the import process of composite assets (or sub-assets) "...are stored in a folder named for the first two digits of the Asset's File GUID. This folder is stored inside the Library/metadata/ folder. The individual Objects from the Asset are serialized into a single binary file that has a name identical to the Asset's File GUID."

    The metadata is in binary format, so it cannot be edited. But it can be deleted, which forces Unity to reimport the asset and recreate the metadata. At least for composite assets, you apparently have to delete both files.