JMan Mousey JMan Mousey - 10 months ago 327
C# Question

Rename animation clips when importing in the Editor

I looked around the docs but didn't see any way to rename a clip as it is imported by a model importer. Is there an API call to name the clips? This is of particular importance because mecanim uses string names for the basis of its api calls and I want clips whose file names are right to have a specific naming convention even if the artist named it something else or will I have to rename thousands of files by hand?

Answer Source

Get ModelImporter from AssetImporter. You can then get the animation clips from ModelImporter.defaultClipAnimations. Loop through the animation clips, rename each one then save it.

Something like this:

using UnityEditor;
public class CreateAnimationClip : AssetPostprocessor
    void OnPreprocessAnimation()
        ModelImporter modelImporter = assetImporter as ModelImporter;

        ModelImporterClipAnimation[] clipAnimations = modelImporter.defaultClipAnimations;

        //Modify/Rename animation clips?
        for (int i = 0; i < clipAnimations.Length; i++)
            clipAnimations[i].name = "Your New Clip Name";

        //Assign modiffied clip names back to modelImporter
        modelImporter.clipAnimations = clipAnimations;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download