- Home /
Resources.Load dynamic path
Does Resources.Load support any kind of dynamic path names, in some sort of form or syntax?
Folder Structure.
FolderName
meshCharacter
meshCreature
someMesh
Will load all gameobjects.
GameObject[] items = Resources.LoadAll("FolderName") as GameObject[];
Will load just two of them.
GameObject[] items = Resources.LoadAll("FolderName/mesh%") as GameObject[];
Answer by fafase · Feb 28, 2015 at 12:43 PM
GameObject [] LoadSpecific(string path)
{
GameObject[] items = Resources.LoadAll("FolderName") as GameObject[];
if(items.Length == 0 ){ return null; } // or empty array
List<GemeObject> list = new List<GameObject>();
foreach(GameObject o in items){
if(o.name.Contains(path)) // Could use StartsWith if you expect the word to be on the front
{
list.Add(o);
}
}
return list.ToArray();
}
I wrote almost the same thing, but the problem is the optimization, you still have to load all of the objects, even if you need only one or couple. But i guess either i have to rethink the load structuring or use this type of search.
You can use the extra parameter from LoadAll to filter by type but that just means unity does the filtering, it is not skipped.
Answer by GameVortex · Feb 28, 2015 at 11:38 AM
No, Resources only have the possibility to load specific assets or all assets of specific types in a folder. You could sort those assets into more subfolders and only load all content in those.
Subfoldering might work, but that way i must know what i load.
Your answer
Follow this Question
Related Questions
Resources.Load folders path? 2 Answers
Loading in Sprites outside of unity? 1 Answer
Get path to loaded resource. 1 Answer
Dynamically load AudioClip during runtime 1 Answer
How to get Assets path and to load an asset with out AssetsDatabase? 2 Answers