Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Force FBX file to refresh/update its Animation Clips when new clips are added?

Discussion in 'Editor & General Support' started by dgoyette, Apr 4, 2024.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,203
    When an FBX file is initially added to a project, Unity will automatically set up the Animation Clips for that FBX.:

    upload_2024-4-4_11-50-33.png

    However, if more animations are added to the FBX, Unity will not automatically import them. (For example, if I export a new version of an FBX with new animations, overwriting the old version of the FBX.)

    So far, the only way I've found to get the FBX to show the added animations is to click the "+" at the bottom of the FBX Clips window, then find the new clip in the dropdown. This is pretty slow, and error prone.

    I was hoping there was some way to force the FBX file to automatically reconcile the clips. Reimporting the FBX doesn't do this, and I don't see a way to keep this from being a very manual process.
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,203
    I found the answer to my question in this old thread:

    https://forum.unity.com/threads/re-import-reset-animation.507392/

    You'll need to create an editor script to do this, but the basic idea is to load the ModelImporter for the FBX, and assign the defaultClipAnimations to the clipAnimations property. Seems to work fine. Here's a minimal approach:

    Code (CSharp):
    1. var path = "Assets/Models/Characters/CC/Leo/LipSync/LeoLipSync.fbx";
    2. var importer = AssetImporter.GetAtPath(path) as ModelImporter;
    3. importer.clipAnimations = importer.defaultClipAnimations;
    4. AssetDatabase.ImportAsset(path);
    5. AssetDatabase.SaveAssets();
    It would be nice if this were just an option available in the Inspector, or right-click context menu for FBX files...
     
    spiney199 likes this.