Efficient way to find all prefabs that are using a script component?

one easy but inefficient way is to e.g in Bash, iterate all the .prefab files in the project, and check if the .prefab file contains the guid of the script. but this is slow. Is there an efficient way to find all prefabs that are using a script component?

Hey ! I strongly recommend reading the full Search documentation here.
For your case, pop open the search window, and either use the + icon to create your query or type
prefab:any t:BoxCollider
replace BoxCollider with the name of the script you are looking for

1 Like

Hi @eerop1111,

I am unsure if you want to be able to see prefab with certain components in the UI or if you want to write a snippet of code to iterate on all such prefabs. I will try to answer both questions.

You can see all prefabs with certain components in the Search Window:
1- Open the search window with Control+K or using the button in the main tool bar

2- In the Search Window select the project are and either type a query t:<prefabcomponentname>

3- Alternatively, you can use the Query builder to look at the available filters or types you can search for:

If you need to use an API to iterate on such prefabs, you can use the SearchService.Request API.

public static void RequestAll()
{
    SearchService.Request("t:texture", (SearchContext context, IList<SearchItem> items) =>
    {
        Debug.Log("All Textures");
        foreach (var item in items)
            Debug.Log(item);
    }, SearchFlags.Debug);
}

I hope this helps.

Seb