How to create .anim file from .fbx file in Unity?
Asked Answered
L

3

8

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.

rig model animations import settings

Lucero answered 26/3, 2014 at 13:6 Comment(0)
L
1

You have to set the animations up in the importing. Select the .fbx model in Unity and go to Animations tab. There you have to define the clips. The .anim files will be generated under the model.

If you do not see the clips inside the animations tab, change the "Animation Type" under Rig to Legacy.

Lundquist answered 26/3, 2014 at 13:33 Comment(4)
That helps, thanks Esa. I have followed your instructions and the code runs ok but still no .anim files are generated, can you explain the reason or show me some links?Lucero
@beyonddoor Could you add screenshots of your model import settings from Unity?Lundquist
screenshots are attached.Lucero
@beyonddoor Looking at the screenshots everything looks OK. Even the run animation is listed in the animation component.Lundquist
L
16

I finally found the answer, pressing CTRL+D on animation clip in .fbx file will create a separate .anim file, what a strange operation!

Lucero answered 26/4, 2014 at 6:37 Comment(1)
Makes sense, ctrl D is duplicate. I guess it defaults to duplicating as a separate file.Urano
P
4

I wrote a script to do this easily

enter image description here

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();
    }
}
Photodisintegration answered 29/6, 2021 at 12:27 Comment(0)
L
1

You have to set the animations up in the importing. Select the .fbx model in Unity and go to Animations tab. There you have to define the clips. The .anim files will be generated under the model.

If you do not see the clips inside the animations tab, change the "Animation Type" under Rig to Legacy.

Lundquist answered 26/3, 2014 at 13:33 Comment(4)
That helps, thanks Esa. I have followed your instructions and the code runs ok but still no .anim files are generated, can you explain the reason or show me some links?Lucero
@beyonddoor Could you add screenshots of your model import settings from Unity?Lundquist
screenshots are attached.Lucero
@beyonddoor Looking at the screenshots everything looks OK. Even the run animation is listed in the animation component.Lundquist

© 2022 - 2024 — McMap. All rights reserved.