Search Unity

Modifying animation clip names during import

Discussion in 'Animation' started by sidwasnothere, Oct 19, 2018.

  1. sidwasnothere

    sidwasnothere

    Joined:
    May 3, 2018
    Posts:
    6
    Hey, I'm trying to create an importer script that renames animation clips. I can edit the animation clip names manually in the editor but for some reason this just isn't working with the script. I'm going to be importing new and updated models regularly for a while so it would make my life way easier if the animation clip renaming is automated. The 'animation type' is generic rigs. Anyone know why this isn't working/what I can do about it? Here's the code:

    Code (CSharp):
    1. void OnPostprocessModel(GameObject gameOb)
    2.     {
    3.         if (assetPath.ToLower().Contains("/pieces/"))
    4.         {
    5.      
    6.             var importer = (ModelImporter)assetImporter;
    7.  
    8.             var animNameList = new List<string>(new string[] { "anticipation", "attack", "idle", "special", "invalidmove", "awake" });
    9.  
    10.             ModelImporterClipAnimation[] clips = importer.defaultClipAnimations;
    11.  
    12.             foreach (ModelImporterClipAnimation clip in clips)
    13.             {
    14.                 foreach(string generic in animNameList)
    15.                 {
    16.                     if (clip.name.ToLower().Contains(generic))
    17.                     {
    18.                         Debug.Log("clipname: " + clip.name);
    19.                         clip.name = generic;
    20.                     }
    21.                 }
    22.             }
    23.  
    24.         }
    25.     }
    Edit: Just in case anyone has this same question, I realized what I really should've been doing is trying to change animator state names, not the animationClips themselves because while scripting for animations I only really had to deal with animation states themselves
     
    Last edited: Nov 1, 2018
    odaimoko and Brain_Xu like this.