- Home /
SetAnimationClip on mecanim State using script
I have an AnimatorController and I'm trying to set the motions used on each of its states using an editor script. The issue is that I'm getting the clip animation from a model importer, and I can't find a way to use these as AnimationClip.
     UnityEditorInternal.AnimatorController ac =  AssetDatabase.LoadAssetAtPath(sourcePath, typeof(UnityEditorInternal.AnimatorController))as UnityEditorInternal.AnimatorController;
     
     UnityEditorInternal.StateMachine sm = ac.GetLayer(0).stateMachine;
     UnityEditorInternal.State state = sm.GetState(0);
     
     ModelImporter mi = AssetImporter.GetAtPath(fbxPath) as ModelImporter;
     ModelImporterClipAnimation[] clips = mi.clipAnimations;
     
     state.SetAnimationClip(clips[0]);
I get 2 errors: The best overloaded method match for UnityEditorInternal.State.SetAnimationClip(UnityEngine.AnimationClip)' has some invalid arguments Argument #1' cannot convert UnityEditor.ModelImporterClipAnimation' expression to type UnityEngine.AnimationClip'
tell me if you succeeded in editing the motion clips of states dynamically. However I think the better approach is to just edit the AnimatorController on the Animator component dinamically.
Your answer
 
 
             Follow this Question
Related Questions
Mecanim - How to figure out the State and layerIndex that triggered Animation Clip Event? 0 Answers
Mecanim - changing animation clip speed, through script? 4 Answers
Animator - How to change the motion (Anim Clip) on a STATE through scripting? 1 Answer
Mecanim - State Behavior - Select motion clip to play at runtime 0 Answers
How to sort motion clip list in Animation Window ? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                