Load external files at runtime

I’m trying to work out loading user created content at run time. Namely, I’m having trouble figuring out how to load 3d object files.

Some of the data is stored in XML files, which I can load using the .Net XML libraries easily enough. Textures and sound can be loaded using the WWW class. But still can’t find a reasonable way to load object files, short of writing my own parser, which I’d rather not have to do.

I’ve found the Resources.Load() function, but from what I can tell this will only load bundled asset data.

Specifically what I intend is to load user created content from the data folder (as returned by Application.dataPath).

Are there any options already available for this? Or does someone have a parser already created, perhaps?

Thank you,

I have an .obj reader script available for licensing if you’re interested. You can see a demo here.

–Eric

You can load external unity web data using WWW.LoadUnityWeb. Read the docs on that for some more info about that.

Have you found Asset Bundles yet?

Asset bundles won’t due. End users need to be able to create content without owning a license to Unity. I just need to be able to load a 3d model from an external file.

The docs on Resources.Load() seem a bit non specific. From what I’ve seen it seems to imply that a resources folder will get bundled with the rest of the assets at build time. If it’s possible, how do I use Resources.Load() to import files that aren’t included in a built Unity app?

Ideally, I’d like to load imported resources from the Application.dataPath directory.

The only way to do that for 3D content is to write an importer. Resources.Load() does what the docs imply (i.e., resources get bundled with the rest of the assets at build time, whether they are actually used in your project or not).

–Eric

Bingo.

Can you point me in the right direction so I can read about how to write an importer (XML based in my case)

Thanks

That depends on exactly what you want to do. If all you’re looking for is an example of an XML loader in Unity, I wrote this script a while back:

http://www.unifycommunity.com/wiki/index.php?title=PropertyListSerializer

That script takes a hierarchical series of hashtables and can export/import it as a property list, which is an XML file designed to handle key/value pairs. For most Unity users, I don’t know if it’s much help, but it has its uses. I created this to serve a very specific need in which I wanted to be able to load user editable XML data files. This can do just that, and doesn’t require the files to be bundled with the Unity build.

If nothing else, this should provide a good example of using some of the .Net XML API.

I’m working on an X3D importer, you can find it on SourceForge by searching for UnityX3D. The archive there is old, but it does import some things, so you can see how to create objects and add textures on-the-fly.

http://www.unifycommunity.com/wiki/index.php?title=ObjImporter