- Home /
 
How to make the ModelImporter NOT to play automatically animations ?
I am trying to import my animations automatically with the post processor. I found all the detailed goodies in the manual and the forums, except the ability to disable autoplay. Something like ModelImporter.PleaseDoNotPlayAnimationsAutomatically Seriously now... the "animation.playAutomatically = false;" doesn't work neither the "ModelImporter.animation.playAutomatically = false;" How should I find my root gameObject and tell it not to autoplay animations from the editor?
 Any ideas or suggestions? thanks. 
 using UnityEngine; using UnityEditor; using System.Collections;
 
                        public class AnimationPostProcessor : AssetPostprocessor
         {
             void OnPreprocessModel()
             {
                 ModelImporter modelImporter = assetImporter as ModelImporter;
                modelImporter.globalScale = 1 ; 
                if (assetPath.Contains("animdoor")){
                                 modelImporter.splitAnimations = true;
                     modelImporter.generateAnimations = ModelImporterGenerateAnimations.InRoot;
                     // Set the number of animations here
                     int numAnimations = 2;
                     ModelImporterClipAnimation[] animations = new ModelImporterClipAnimation[numAnimations];
                     animations[0] = SetClipAnimation("dooropen", 0, 50, false);
                     // Add your new animation splits here, simply changing the arguments
         animations[1] = SetClipAnimation("doorshuts", 50, 100, false);
                     // Add your new animation splits here, simply changing the arguments
                     // Assign the clips to the model importer to automagically do your splits
                     modelImporter.clipAnimations = animations;
                 ///
 
               /// animation.PleaseDontPlayAutomatically = true;???? /// }
 
                            }
             private ModelImporterClipAnimation SetClipAnimation(string name, int firstFrame, int lastFrame, bool loop)
             {
                 ModelImporterClipAnimation mica = new ModelImporterClipAnimation();
                 mica.name = name;
                 mica.firstFrame = firstFrame;
                 mica.lastFrame = lastFrame;
                 mica.loop = loop;
 
               /// animation.PleaseDontPlayAutomatically = true;???? return mica; }
 
                        }
 
                
              Answer by Lucas Meijer 1 · Apr 13, 2010 at 06:30 PM
Instead of using the preprocess hook to setup import settings, you could use the postprocessor, to modify the hierarhcy of gameobjects & components (including the animationcomponent that you're interested in) that has been generated by the import process.
It works like this:
- unity imports a model
 - unity gives you a change to change it
 - unity saves the imported results to disk
 
Brilliant yes ... ! Sometimes your $$anonymous$$d sticks in one idea and the solution is just in front of you .. .
Your answer