- Home /
How can I retrieve the animation clips inside an animation fbx file?
I'm trying to get all the animation clips stored inside an fbx file. The fbx file is an asset, NOT a Game Object, i.e: it shows in the project's window, not in the hierarchy.
What I want is a method to access the Motion object in the animation file, as I'm building an script to automatically map motions to mecanim states/animationclips given a set of filename named with some conventions.
I've tried:
Accessing the motion inside the fbx file directly. Unfortunatley the fbx file is of type
UnityEngine.Object
and does not includes an Component of type Animation.Instantiating the fbx file in the scene (so I create a proper GameObject from that asset) and then accessing the
GameObject.animation
property. Unfortunately when I instantiate it the resulting GameObject in the hierarchy, it does not contains an Animation Component neither so I'm pretty stuck.
Any ideas?
Thanks @CodinRonin I've solved it. The solution is to load the fbx file asset specifically as an AnimationClip
i.e.: AssetDatabase.LoadAsset(path, typeof(AnimationClip))
Doing so the FBX loads fine, yay!
I was trying to load the FBX as a typeof(GameObject)
so I could access the Animation Component. It turns out that loading it that way was wrong.
Thanks for the link, if you want to write down this very same answer so other can see it at a glance I'll accept it
I have the same problem, but my need is to get ALL the anim clips inside an fbx. An fbx can contain multiple anim clips when it has multiple takes (from motionbuilder). All the answers I found so far, including here, assume that there is only 1 anim clip per fbx...
Answer by CodeElemental · Feb 26, 2014 at 09:35 AM
Here , You can find a script that copies the animation curves from an imported .fbx file into unity animation. The script creates a read/write copy of the animation in the same folder. It treats the fbx files as assets so it might prove useful.
As accepted from OP the line :
AssetDatabase.LoadAsset(path, typeof(AnimationClip));
proves to be helpful.
Your answer
![](https://koobas.hobune.stream/wayback/20220613134800im_/https://answers.unity.com/themes/thub/images/avi.jpg)