- Home /
How to look for a material in Assets folder and sub-folders?
Maybe I can't figure this out because it's late and I can't think straight, but how do I look for a material in the Assets folder and all its sub-folders?
For example, I want to return a list of all materials named "Black" found in my project's folder(s), so I know not to create it if it already exist somewhere else.
Thanks for your time!
So there isn't a Unity class to do that? What about using AssetDatabase.Contains(Object)?
I haven't used the AssetDatabase class myself, as I tend to keep my assets organized into folders and sub-folders and so find using the IO class a far better solution.
Looking at the script reference, the Contains()
method that you mentioned only returns whether the passed object is an asset (exists in project) or not (exists only in scene, e.g. instantiated at run-time).
For what you are looking for (searching for assets by name), I would again use the IO class to search recursively through all the folders in the project (using depth-first approach).
Answer by asafsitner · Feb 19, 2012 at 02:11 PM
Take a look at c# File and Directory classes (System.IO). Note that this will only work in the editor.
Your answer
Follow this Question
Related Questions
Metadata not being saved on custom file types 0 Answers
OnPreprocessModel() override for individual changes??? 1 Answer
Is there a way to get a unique hash for an asset? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Storing a part of a complex asset in an asset bundle 1 Answer