Loading mesh from StreamingAssets

I’ve tried many different ways to go about this and couldn’t find any results. I don’t want to use Asset Bundles, I want to be able to put a .fbx (or other model extension) into the streaming assets folder and then load it into a mesh on a gameobject. I’ve googled this issue for awhile now and after trying many of their methods as well as my own, I can’t find a solution:

I need:
*To load a .fbx from StreamingAssets and apply its mesh to a gameobject.

For some odd reason, Unity is importing assets in StreamingAssets differently than it would normally. Any and all help is appreciated:

The code that doesn’t work: (And I’ve tried many variations of this code):

        string path = "Assets/StreamingAssets/Default/Models/Soldier1.fbx";
        Mesh mesh = (Mesh)Resources.Load(path,typeof(Mesh));
        GetComponent<MeshFilter>().mesh = mesh;

The code inside of unity that can import a fbx to a mesh is only inside the editor.
If you need runtime loading of models you need to use a script / asset that does that for you (unless you like to build it yourself)
A quick search for “Unity FBX runtime importer” did show me this asset

there are other out there that you have to check and choose for your project fitting.

PS: Resources.Load does only load assets that are inside the resources folder and are not a real folder in the build application like the steamingassets folder.

(This is all to make my game able to be modded) Does this mean that normal everyday people would be unable to just throw an FBX in a folder and have a script call it?

If you use a “Unity FBX runtime importer” Asset then they can. You can use the www class or the file class to read your fbx file from disk and then load the mesh via that importer asset.

Even though this post is old, it still shows up when people like me search for loading meshes. The information in it is incomplete, and now outdated, so just to update this post for 2020, I will mention that I have tried the very few FBX runtime-importers for Unity (so far) and I haven’t seen any that will load a model properly. Some don’t work at all, some just load a distorted model, and none seem to be able to properly import animations and/or textures. So… I will mention the new Unity-compatible format (which hasn’t even been mentioned here) GLTF. For those who don’t know, GLTF is purposed to become the new standard in 3D model formats, currently supporting more features than even FBX does. It is also an “open-source” format, unlike FBX. Also, it does not rely on C++ as FBX does, and GLTF files are “human-readable” and can be edited in any basic text editor since they use XML. It can also contain animations just like FBX can. There are already working runtime-importers for the GLTF format in Unity, and they are free.

One other thing to mention, the WWW class in Unity is now obsolete, and must be switched with UnityWebRequest.

3 Likes

Bump for this, thanks.

1 Like