3
\$\begingroup\$

Unity allows me to add multiple labels to my assets in the editor (the little blue luggage tag in the corner of the inspector). I can use the Asset Database to find all assets with a certain tag from the editor, but can I do the same thing at runtime? Maybe if the assets are in the resources folder?

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Unfortunately, you can’t access the labels during runtime.

As you said methods like AssetDatabase.GetLabels and AssetDatabase.FindAssets are part of the namespace UnityEditor, which can’t be used in runtime.

But what you could do is: Write a editor script that export that all the labels information into a file and then in runtime read in that file, then you have a mapping of asset name to list of labels

// mapping labels by name
Dictionary<string, List<string>> labelsByName = ...;

// loaded texture 
Texture2D texture = ...;

// get labels of the texture
List<string> labels = labelsByName[texture.name];
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .