- Home /
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.
Answer by matfrem · Mar 20, 2013 at 04:18 PM
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
}
Answer by zyzof · Sep 04, 2012 at 03:09 AM
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)
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!