Loading FBX Elements from Script

Lets say I loaded an FBX using “Resources.Load(“MyFile”)”. In that FBX file I have meshes and animations. I have my resource stored as an “Object”. How can I access meshes and animations separately?

T[ ] Resources.LoadAll(path)

You don’t need to load the asset first, you can get the contents. So if you have a file called my_fbx.fbx in your Resources folder you can do:

        // get all the meshes in my_fbx.fbx
        Mesh[] meshes = Resources.LoadAll<Mesh>("my_fbx");
        // get all the anim clips
        AnimationClip[] anims = Resources.LoadAll<AnimationClip>("my_fbx");

Just as a side note, there is overhead with fbx files. If you are pulling them from resources, the fbx is included in the build. If you are really only using the meshes and anim clips, you could extract editor side and just include those assets. I recently did exactly this. I had several hundred source .fbx files and only needed the mesh data. I tested extracting just the mesh and saving them as assets and not including fbx(s) it reduced from 72mb to ~6mb. Just food for thought.

2 Likes

Thanks for tips! :slight_smile:

How about loading characters? Lets say I have a model made in Blender which contains: meshes, bones/rig, textures, animations. I export it as FBX. I suspect I should call “Resource.Load” and it will create a full game object hierarchy for that character. Correct?

No. You should create a prefab, if you mean to use the whole thing as a gameobject. I would only access the fbx directly if you are using discrete elements. And definitely avoid using the resources folder in your game/runtime. It’s useful for editor tasks assets processing, but should be avoided beyond that.

1 Like

Ok, I think I understand it now. I use resources since I manually manage memory. I don’t want to pre-load everything during startup. I load and unload everything as needed. This allows much faster startup and lowers RAM consumption.

It will actually cause longer startup times (among other potential problems) more here:

And eventually it will be deprecated.

But, regardless, yea, the fbx is just a source file, creating a prefab from it and using the prefab is way to go if you intend to use it as a gameobject. You can still load the prefab from resources if you want.

1 Like

OMG! There is O(N*logN) process during resources startup! I have 4000 of just icon files. XD I’m gonna switch to AssetBundles for my memory management. Big thanks man!

1 Like

Assetbundles are a little more complex, but definitely worth the effort, and give you a lot of flexibility long term. Cheers!

I’m looking for a way to access an FBX custom properties on its node.
I have a bunch of models made in 3DS max with tons of custom properties, I would like to be able to access them in unity. I really don’t know where to find those data on my gameObject :confused:

This code produce error.
It is not possible to conver AnimationClip to AnimationClip[ ]
How can I get the other AnimationClips?