Skip to content

Collection Tool

Sebastien Phaneuf edited this page Dec 19, 2023 · 5 revisions

Collection Tool

The Search Window is great at finding antyhing in Unity (Assets, GameObject, Menus, Settings...). But it can be so much more if you put just a little more time with it. It can act as a Collection Tool that could help with lots of Level Editing tasks.

Search Query Asset

Writing a good and precise query can be tedious. As an example:

Give me all meshes in current scene that have no LOD and the triangle count is larger than 2000

h: -t:LODGroup t:MeshRenderer vertices>2000

query

(for more Query Examples see this page)

You wouldn't want to write this EACH time you want to tweak your scene for costly mesh rendering. Enter the Search Query Workflow!

Each time you have a nice Query save it to disk using the nifty diskette icon:

query

You can then double click in the Project Browser to open this query. The whole Search view state: window size, icon size, which panels were opened, table column setup (more on this below) will be preserved in the SearchQuery asset. This effectively becomes a live and dynamic collection of items.

Since the Search Window supports dragging from, these live collection can act as level designer palette containing assets only relevant to some specific workflows: walls, enemies, props, etc.

Some more information in SearchQueryAsset can be found in the Manual.

Why not use folders?

If you organize all your assets in a proper folder structure, having Collection of assets might seem redondant. In my opinion live collection have the following advantages on folder:

  • Ease of navigation: you can put all your search query assets in the same folder and have them readily available for all sorts of workflows instead of navigating the Project Browser to find a single asset. queryfolder
  • You can have multiple Search Window opened at the same time, each showing a different query/collection. queryfolder
  • Search Query are available through the Search Query panel (more on this below). So no need to navigate folder. queryfolder
  • Collection of assets can be setup with a Table allowing powerful multi-editing or properties comparison at a glance (more on this below). query
  • An asset can appear in multiple queries.

Think of Search Query asset as database query where the semantic of the query is more important than the location of the asset itself.

Search Query Inspector

Search Query Asset Inspector are practical in that they even host a list of items that would be yielded by a Query.

query

This list of assets supports drag as well. The Is Search Template toggle is useful to pin a particularly useful query to the Home page of the Search Window:

query

Search Table View

Search Tables are a way to turn the Search Window into your own spreadsheet to allow multi-editing of objects. Setupping a proper table might takes some time but SearchQueryAsset are your friend. If you save a SearchQueryAsset it will be saved with its table configuration.

Unity already has a tool that shows objects in spreadsheet-like manner. It is the Light Explorer Tool. But it is a fairly hardcoded tool and it only works for Lights:

Now you could setup the same kind of table with a Search Table:

But what is best is that you can now create table for any kind of objects. Imagine your game has a Weapon Scriptable objects to store all weapons statistics and icons.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(menuName = "Gameplay/Weapon")]
public class Weapon : ScriptableObject
{
    public Texture2D sprite;
    public int damage;
    public float range;
    public float spashRange;
    public float cooldown;
    public float speed;
    public int projectileCount;
    public bool singleUse;
}

You could setup a Search Table looking like this and allowing easy tweaking of all weapon statistics:

When adding a column to s Search Table you basically need to do two things:

1- Add a new columns using the Add Column + button

When populating the Column Selection tool we trypopulate it with all the available properties available for any objects current listed.

You can even write your own ColumnProvider which allows you to write your own column/cell UI.

2- When a column is added, we add it in readonly mode (it cannot be edited by default). We have multiple column format that defines how to display the column data. We have 2 formats allowing you to edit column data: SerializedProperty and MaterialProperty format.

When modifying a column setup, do not forget to save your search query again!

What about other Search features?

I already covered some of the feature above in our Search Tour which contains many more tips and tricks.

Clone this wiki locally