- Home /
How can I find all the asset labels in my project?
Is there a way to find out all of the asset labels attached to objects in my project? The unity UI knows, but I don't know where that's stored and it does not seem to be documented.
Bonus points: is there a way to set the contents of the search filter bar from script?
I'm not entirely sure what you're asking, can you be a little more specific? Give us an example.
Unity somewhere has a global list of all the labels attached to assets in the assetdatabase - the list you see if you click the tag icon in the project filter bar, for example. I want to find that list.
I gotcha. I wasn't aware there was such a thing, apologies. I see ArkaneX already answered, glad you found what you needed.
Answer by ArkaneX · Nov 08, 2013 at 11:00 PM
You can get all labels calling internal AssetDatabase.GetAllLabels
method via reflection. The internal code might of course change in a future Unity version, but I think it's highly unlikely. I bet you can fill a search filter using reflection too, but this might be a bit harder.
Code for retrieving all the labels:
var flags = System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.InvokeMethod;
var dicLabels = (System.Collections.Generic.Dictionary<string, float>)typeof(AssetDatabase).InvokeMember("GetAllLabels", flags, null, null, null);
foreach (var label in dicLabels.Keys)
{
Debug.Log(label);
}
EDIT: as a side note - this is an editor only script.
Works like a charm, thanks!
Is it possible to remove the built-in ones that aren't relevant?
In case you only want to retrieve labels used in your project, I can suggest using documented AssetDatabase methods. Sample code:
var paths = AssetDatabase.GetAllAssetPaths();
foreach (var path in paths)
{
var asset = AssetDatabase.Load$$anonymous$$ainAssetAtPath(path);
var labels = AssetDatabase.GetLabels(asset);
if (labels.Length > 0)
{
Debug.Log(asset.name + ": " + string.Join(",", labels));
}
}
Please note that in case of composite assets, Load$$anonymous$$ainAssetAtPath will probably not be enough, and you should be using other LoadXXX methods.
Is there a way to search the scene for all objects that are assets with a certain label? I'm trying to search l:Dynamic for objects that have the Dynamic tag but it only finds in the project, not in the scene.
Your answer
Follow this Question
Related Questions
Where are asset labels stored? 1 Answer
Importing custom assets? 0 Answers
Cannot save a generated texture as part of a bundle 1 Answer
How do I import assets from the Asset Store while offline? 2 Answers
Unity Error removes assets - "Rebuilding Library because asset database could not be found!" 0 Answers