- Home /
How to identify/get the file name of resources loaded with Resources.LoadAll
I would like to use Resources.LoadAll to load a bunch of textures. However, how can I identify each loaded resource? I would like to know the filename of each resource, so I can put them in a Dictionary and use the filename as a key to access the textures. Is this possible? Or is there a another/better solution?
Answer by WhiskeyJack · May 12, 2011 at 01:06 PM
Never mind, you can just do object.name to get the filename (minus extension). Typically a case of looking to hard.
It would be nice to get the extension, so you can tell the difference between a jpg and png and so forth though.
just make your own na$$anonymous$$g convention then, either in the end or at the start of the file or place them in seperate folders.
In the case of shaders, obj.name will not be accurate, for example if you have a shader named : "Unlit - Transparent Colored" the name of the object will be transformed in "Unlit/Transparent Colored". I have been searching for some functionnalities of AssetDatabase to achieve the exact desired name result but couldnt find it yet.
Answer by Lou-adrien Fabre · Jun 10, 2014 at 12:53 PM
Read my previous comment, but so far the only really reliable way to find the file name (and not resource name) is the following : Path.GetFileNameWithoutExtension(AssetDatabase.GetAssetPath(obj));
Where obj is the resource object.