How do you find GameObjects in a project that have a specific component?

I have a large project and I want to make a change to a script component, but before I do I want to find any gameobject in the project that has this component as they will each need to chose a different value for the property I’m changing.

I can’t see a way to use the project search to find GameObjects by their component types, am I missing something or is this not available in Unity?

Thanks

There isn’t something built-in, but you could use either the AssetDatabase or the Searcher to get all prefabs in the project (all assets of type GameObject), then do FindComponentsInChildren( true ).

If you don’t want to use a script you might also be able to use Unity’s new Search to find all prefabs with a component, however I can’t say for sure it’ll look in prefab children, and I personally found it to be a bit temperamental.

Yeah, it seems like there are a few tools on the asset store, it just seemed like the sort of thing you’d expect the editor to be able to do.

Cheers and thanks for the response @evyatron

1 Like

Hi!
It is entirely possible to search for gameobjects that have a specific component in your project. You can use the global search for that:
9276435--1299270--unity-search-gameobjects-with-scripts.gif

The project search is limited, but can be modified to use the same advanced search engine as the global search if you wish. All you need to do is to go into “Preferences/Search” and change the search engine to advanced.
9276435--1299273--upload_2023-9-6_12-9-21.png

Hope this helps.

2 Likes

Is there a way to make this work with child components as well?
If I have a component I want to change and need to find all usages of it, I’ll likely want it to search the entire hierarchy of each prefab, and your example doesn’t seem to do that as far as I can tell?

That is also possible, but you need to modify your search index to allow sub objects indexing. You can open the Index Manager through “Window/Search/Index Manager”.
9281800--1300453--upload_2023-9-8_11-44-25.png
By enabling sub object indexing, the indexer digs through scenes and prefabs and indexes the properties and components as if they were on the main asset. For example, I have a prefab containing a cube that has a script component, and another prefab that contains the first one. If I search for any asset with the type of my script, I can find both:
9281800--1300456--upload_2023-9-8_11-49-43.png
Let me know if this is what you are looking for.

3 Likes

Oh nice, yeah that’s perfect, thanks!