Domanda

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

È stato utile?

Soluzione 3

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.

Altri suggerimenti

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

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();
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top