I am new in using Unity. In my game, models and animations are exported from 3DMAX as .fbx files, animations are clipped in Unity, but there's no .anim files generated, I need separated .anim files because the following code will not work even I have clipped animation "run":
var clip = animation["run"];
Can someone help me? thanks in advance.
I finally found the answer, pressing CTRL+D on animation clip in .fbx file will create a separate .anim file, what a strange operation!
I wrote a script to do this easily
using System.IO;
using UnityEditor;
using UnityEngine;
public class AnimationExtractor: MonoBehaviour
{
[MenuItem("Assets/Extract Animation")]
private static void ExtractAnimation()
{
foreach (var obj in Selection.objects)
{
var fbx = AssetDatabase.GetAssetPath(obj);
var directory = Path.GetDirectoryName(fbx);
CreateAnim(fbx, directory);
}
}
static void CreateAnim(string fbx, string target)
{
var fileName = Path.GetFileNameWithoutExtension(fbx);
var filePath = $"{target}/{fileName}.anim";
AnimationClip src = AssetDatabase.LoadAssetAtPath<AnimationClip>(fbx);
AnimationClip temp = new AnimationClip();
EditorUtility.CopySerialized(src, temp);
AssetDatabase.CreateAsset(temp, filePath);
AssetDatabase.SaveAssets();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With