- Home /
Is there a way find usage of an asset?
Is there a way to find all the occurrences of a given asset (where it is being used). i.e the opposite of "select dependencies".
It's easy to click on an asset or prefab and then navigate to its dependencies (for example find the texture used by a given material). I'm looking for the reverse navigate - from the texture find all the materials that use it, if any.
Is there a way to achieve this?
One approach you can use is to do it outside of Unity.
Each asset's meta file contains a guid which is used to refer to that asset in other files. So if you find that guid and search other files for it, you can find the references, whether they're in scenes or prefabs or whatever.
There can be a bit of head-scratching to do to work out how the asset is being used, but often you can work it out from the context in file, and anyway it gives you a comprehensive starting point (you can always then switch to Unity). I find it handy when I'm deleting an asset and want to be sure that it's not being used before doing so.
I'll support that approach, you could create an editor script where you give the items you are looking for and the scenes in which they should be found.
Your scene file is just a YA$$anonymous$$L, so it can be treated like a text file. You can then search whether the GUID of the given assets are present in the scene, If so, you can find what is the object/script that refers to it.
The result can be printed in the Editor window. Easier said than done but this is actually just basic string manipulation. Best is to start with looking at the scene YA$$anonymous$$L file and try to understand the logic behind it.
This tip helped me. Think is useful in bug and complex and messy unity projects.
Answer by Gotlight · Sep 07, 2016 at 09:44 PM
Is there a way to find all the occurrences of a given asset (where it is being used). i.e the opposite of "select dependencies".
Hi! There's a tool which has the opposite core idea to Unity's Select Dependencies. After several major updates, an asset offers great interface for working with results and is much faster.
For example, it offers:
Search for usages of: Scenes, Scripts, Shaders, Materials, Sprites, Prefabs, Textures, Sounds
Search for usages in: Prefabs, Scenes, Atlases, Materials
Search inside Project and inside Scene as well
Asset Store link:
Denis
Answer by BorisOkunskiy · Mar 09, 2020 at 08:30 AM
I know it's been a while, but you can open .meta
file of your asset in question, grab the value of guid
field and then simply search by this value through all the files (e.g. by using git grep <my_asset_guid>
).
This gives you a really quick and useful outlook of whether the asset is used and where exactly. Of course it might not fit every bill, but this is my favorite way of "finding usages" because it's virtually agnostic to Unity version and doesn't depend on any extra downloads or scripting.
Answer by Catlard · Oct 23, 2011 at 11:36 AM
Here:
var go : GameObject;
var gos = GameObject.FindGameObjectsWithTag ("TAG YOU THINK YOU WANT");
//finds all gameobjects of that tag, loads them into an array
for (go in gos)
{
if(go.renderer.material == " MATERIAL NAME HERE")
{
print(gameObject);
}
}
hopefully you've got a good idea of which tags you're looking for.
O$$anonymous$$ so your answer told me that there is no simple built-in way to do this in Unity and that I have to resort to code. However it has to be an Editor script and is more complicated than simply finding objects by tags. So I created a little editor script to achieve this.
Thanks for your answer, it definitely put me on the right track.
Answer by Sarchophagi · Nov 02, 2019 at 05:14 AM
Use the following FREE asset. Instructions are on the link. Really great.
https://github.com/yasirkula/UnityAssetUsageDetector
Answer by Catlard · Oct 23, 2011 at 11:15 AM
When I want to find this out, usually I take the asset out of the project, or make it cause an error in some way--and then all the objects with that asset will throw errors. This works for scripts, which is usually what I'm looking for when I'm doing this. Does that answer your question?
I'm trying to do this with other assets like textures and materials. If I delete a used texture or material (or any other non-script asset) I don't get errors. Ins$$anonymous$$d things just appear incorrectly, sometimes in subtle ways.
See my comment to the question above - it describes a way of reassuring yourself that an asset is not being used.
Yes, this is a trickier business. I suppose the easiest way to do it then would be just to identify them by code, a la a function that goes through every game object. Here's some code that might do it for you, in the next answer.
Removing a script won't make the editor reporting it as an error. You'll get a warning for a missing script and empty components in your game objects, without the missing script name. Not that useful.
Your answer
