- Home /
Change AnimationClip settings during import
I have a group of animations that need to have the LoopTime set to True (Idle, Walk, Run). I would like to set this setting during import time using an AssetPostprocessor.
I've already tried using OnPreprocessModel and OnPostprocessModel but haven't had luck with them. Basically I noticed that I could do:
 ModelImporter modelImporter = assetImporter as ModelImporter;
and access modelImporter.clipAnimations, but this array is always empty. I managed to populate it using
 ModelImporterClipAnimation clipAnimation = new ModelImporterClipAnimation();
 clipAnimation.firstFrame = [FIRST_FRAME]
 clipAnimation.lastFrame = [LAST_FRAME]
 clipAnimation.name = [ANIM_NAME]
 clipAnimation.loopTime = true;
                           
 ModelImporterClipAnimation[] clips = new ModelImporterClipAnimation[1];
 clips[0] = clipAnimation
                
 modelImporter.clipAnimations = clips;
But I cannot find a way to get the values for [FIRST_FRAME], [LAST_FRAME] and [ANIM_NAME].
I'm using just one animation per FBX, so basically the length of the clip gets detected by Unity automatically
Answer by codeage · Jun 30, 2016 at 02:30 PM
You can get the clips from ModelImporter.defaultClipAnimations, modify the import settings and then assign it back to ModelImporter.clipAnimations.
 ModelImporter modelImporter = AssetImporter.GetAtPath(file) as ModelImporter;
 var defaultClipAnimations = modelImporter.defaultClipAnimations;
 foreach (var clipAnimation in defaultClipAnimations)
 {
     clipAnimation.loop = true;
     clipAnimation.loopTime = true;
     clipAnimation.loopPose = true;
 }
 modelImporter.clipAnimations = defaultClipAnimations;
 modelImporter.SaveAndReimport();
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                