AnimationClips from an fbx file to script
Hello!
I have a problem with pulling actual references of AnimationClips from an .fbx file via script.
Workflow: I'm importing .fbx and cutting animation via script in multiple animations during preprocessing, and then through editor window i input it into Animator and database.
But the only way of getting actual reference of animationClip i found was to get it through LoadAssetAtPath(), and this gets only first one of them( i have 3+ animations in each fbx).
Other way is to instantiate an object, and then i get a copies, but i need references to actual ACs in fbx. Is there any way around this two? Maybe some method like LoadAssetAtPath which lets to get multiple objects of certain type from AssetDatabase?
My project has tons of animations and i want to automatize work with database and animator as much as possible. Of course i can just drag and drop this animations to animator, but where is fun in that(and animator is laggy af after 300+ animations)
Help much appreciated asap. Thank you!
Answer by Niknokc · Jan 12, 2017 at 09:55 AM
Well... I've never believed that legends about finding answer right after asking question were true, but, well this is the case.
I found a solution:
UnityEngine.Object[] data;
data = AssetDatabase.LoadAllAssetRepresentationsAtPath(myPath);
clips = new AnimationClip[numOfClips];
int t = 0;
for (int i = 0; i < data.Length; ++i) {
if (data[i].GetType() == typeof(AnimationClip) &&t<clips.Length) {
clips [t] = data [i] as AnimationClip;
++t;
}
}
It is fairly simple. I'm parsing all assets in fbx file, knowing number of animations that i need(numOfClips). And then adding found animationClip Objects to clips array "as AnimationClip"
Good luck.
Hi I tried this also but apparently AssetDatabase is part of the unity editor namespace, which doesn't work when built, so do you know another way>?
Hey, @yaakovyitzchakbenmoshe Generally you don't have fbx files in built version. You should preprocess all models beforehand. This question was generally work on smarter version of imputting a lot of animation files without need to set required settings manually. Why do you need to parse through fbx file when app is already built?