x


Can AssetDatabase.LoadAllAssetsAtPath Load All Assets Recursively?

I'm confused by the documentation for LoadAllAssetsAtPath. It reads:

*Returns an array of all asset objects at assetPath.

Some asset files may contain multiple objects (such as a Maya file which may contain multiple Meshes and GameObjects). All paths are relative to the project folder. Like: "Assets/MyTextures/hello.png"*

I know some assets contain multiple objects. Would a path such as:

"Assets/BunchOfStuff/"

load all the assets under BunchOfStuff recursively? It doesn't appear so. When I call:

AssetDatabase.LoadAllAssetsAtPath("Assets/SomeDirectory");

As a path that contains child assets, I get two Objects returned. It doesn't matter if there are more assets under that part or no assets at all. Always 2 are returned. I'm not sure what they are.

I'm trying to script an automated build for a bunch of asset bundles containing a large amount of content (text and images). I don't want to have to enumerate all the assets I want included in the case where every asset should be included. I've seen the simplified example scripts but I've not seen any yet that handle a bunch of assets.

more ▼

asked Aug 03 '10 at 08:01 PM

Ben 2 gravatar image

Ben 2
473 20 24 41

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

AssetDatabase.LoadAllAssetsAtPath() only works if you specify the path of a single object. It will load all the assets that are children of that asset.

It sounds like you want to use Resources.LoadAll(path), which will load all the assets at the specified relative path inside any folder named "Resources" (you might have to rename/rearrange your project hierarchy)

more ▼

answered Sep 04 '12 at 03:09 AM

zyzof gravatar image

zyzof
1

Are you suggesting that our asset we would wish to make asset bundles with should be in the Resources directory? I don't want these assets in my Build... I guess I could create subdirs in resources for each thing i wanted to bundle. Ben 2 - how did you go about solving this? right now I'm looking into using c# to simply iterate through all the files in a folder I want to use for an assetBundle and then manually create a list of objects based on my list of files. thanks all!

Dec 21 '12 at 06:13 AM wrxmarcus
(comments are locked)
10|3000 characters needed characters left

You can just list all files usung file listing and load them one by one:

string[] aMaterialFiles = Directory.GetFiles(Application.dataPath, "*.mat", SearchOption.AllDirectories);
foreach(string matFile in aMaterialFiles)
{
    string assetPath = "Assets" + matFile.Replace(Application.dataPath, "").Replace('\\', '/');
    Material sourceMat = (Material)AssetDatabase.LoadAssetAtPath(assetPath, typeof(Material));
         // .. do whatever you like
}
more ▼

answered Mar 20 at 04:18 PM

matfrem gravatar image

matfrem
1 1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x685
x428
x396
x351
x15

asked: Aug 03 '10 at 08:01 PM

Seen: 2699 times

Last Updated: Mar 20 at 04:18 PM