Search Unity

The latest in Search: Unity 2021.2

January 19, 2022 in Technology | 9 min. read
3 spheres on black background
3 spheres on black background
Topics covered
Share

Search has substantially transformed this past year. From the Quick Search package, focused on finding Unity objects by name, to the Core Search workflow with detailed criteria that allows you to save searches, review items, and use a LINQ-like language to create complex queries, it’s time to experience the latest.

Initially released in version 2021.1, Search has since become a core workflow for Unity users. In fact, it’s built directly in-Editor so there’s no need to install the package manually.

To use this tool effectively, you can type in a few characters and act on the returned set of objects or create more complex queries. The latest version of Search, in Unity 2021.2, ensures ongoing productivity through a series of major improvements. Read on to explore those changes.

* Please note that there is an experimental preview of the Quick Search package that works with 2020.3 and contains almost all of the same features as the Core version. To install the latest preview package, you must go to Project Settings and enable Preview Packages.

Improved indexing performance

Today, our Asset Indexing System is more performant than ever. Not only does the initial indexing take less time and space, but you can increase the amount of data being indexed by tweaking the default index from the Index Manager (Window > Search > Index Manager).

Unity Search indexing

By adding indexing for both Properties and Dependencies, you can make the most out of the new Search Picker and Table workflows, as shown above.

Saved search organization

Our next big improvement lies in the incredibly powerful Save Searches workflow. We know how tedious it can be to type the same queries over and over again, so we added a brand new organizer for saved searches.

Unity saved search organization

Here are the new options available to you: User Searches (saved in your preferences) belong to you and only you, whereas Project Searches (saved as an asset in your project) are shared with all project contributors. You can bind an icon to search, and open searches in a new Search window. The whole state of the Search window will persist with your search – meaning that the query text, icon size (especially for your Table layout), and selected Search tab will always be restored.

Search Table view

The Search window allows you to visualize objects in different ways: Compact List view, Big List view, or multiple sizes of grid icons, as shown below.

In Unity 2021.2, you can visualize the resulting items of a query in Table view:

This is useful for sorting items by name or description. And it gets even better when you consider the ease with which you can extract properties from Search Items using a Search Expression to create a column layout that looks like this:

Of course, taking the time to set up a column layout is only useful if you can save it. As previously mentioned, the whole state of the Search window – including column specifications – will persist in your search. You can even create your own Data Explorer to compare and contrast multiple property values against each other.

When a Table column’s layout is set up, use the Save icon to save all of its information in a CSV or JSON file and produce detailed reports. This facilitates the process of reviewing and comparing multiple versions of the same project.

Search Picker

The next feature is sure to please more advanced Unity users. If you seek further precision when selecting assets, game objects, or just about any other object in Unity, you can now use the Search window in lieu of the Legacy Object Picker. This enables you to define how specific Script properties are determined via code.

By using the [SearchContextAttribute], you can decorate any Object reference property. Simply select a set of Search Providers for a query, an initial more constrained query, or Search View Flags to alter the appearance of the Search Picker.

This is what the above specification looks like:

Notice how an initial query has been set up in the Search Picker view, displaying a grid of icons.

Search Expression

Finally, we’ve added the concept of Search Expression. Search Expression extends the Query Language to make it more powerful and customizable. But what does Search Expression actually help you do?

  • Express a single statement query that might cross-reference multiple search providers, or run multiple queries at the same time.
    • i.e., Show me all objects in my current scene referencing shaders that do not compile.
  • Apply transformation and filtering to a set of items yielded by a query – think LINQ meets SQL meets Lisp (for the S-Expression syntax).
    • sort{count{...groupby{a:assets, @type}}, @value, desc}
    • select{t:LODGroup, @lodsize}
  • Pair with the Search Table workflow to run complex queries on a project and display this information in a tabular fashion. Search Expression can be used for the foundation of a Continuous Integration or Validation system.

While the syntax of Search Expression is rather vast, we’d like to give you an idea of the query types you could run into (good or bad):

Find all Prefabs referencing any texture with the name “rock”:

t:prefab ref={t:texture rock}

This means that the system will run the query t:texture rock. Then, the query t:prefab ref=<rock> will run for all those textures. The results of those queries will be aggregated to show the final results.

Find the number of distinct asset types in my project:

count{t={distinct{select{a:assets, @type}}}}

Compute the average LODSize of all LODGroup assets in my project:

avg{select{t:LODGroup, @lodsize}}

Whenever you see curly brackets, think Search Expression. Then think of the evaluators avg, select, distinct as processors for item streams. Evaluations occur in a thread that runs in the background of Unity, so regardless of the complexity or the number of queries you need to run, the Search window will remain as responsive as possible.

Search queries also let you save those long Search Expressions, making it easier to run them without retyping the entire statement.

Feedback and more information

All of the workflows presented here are covered in the official Unity Editor documentation.

Additionally, we’ve put together a public GitHub repository with all sorts of query examples and even some prototyping tools based on the Search ecosystem. 

Our Wiki similarly contains articles on the wonderful Search workflows, with a detailed section unpacking the intricacies of Search Expression.

The Query Examples page offers a sneak peek of new features coming for Search in 2022.1:

To learn more about what we’re working on for Unity 2022.1, check out the beta launch blog post.

January 19, 2022 in Technology | 9 min. read
Topics covered