Search GameObjects with the Hierarchy search provider
Use progressive caching to search GameObjects in loaded scenes.
阅读时间7 分钟最后更新于 10 天前
The Hierarchy search provider searches all loaded scenes, including inactive ones.
The search uses progressive caching, not an index, so you can use it even if your project has no indices.
Query syntax
Provider token: (for )
h:HierarchyQuery examples
Query example | Description |
|---|---|
| Find all GameObjects in the scene that have the word |
| Find all meshes in the scene that are bigger than 4096 vertices. |
| Find all renderers in the scene using M_Metal01 material. |
| Find all cameras in the scene whose field of view property is greater than 70. |
| Find lights in the scene on layer |
| Find all mesh renderers in the scene that are static shadow casters. |
| Find objects in the scene by layer and tag. |
| Find all sprites in the scene with the |
| Find all sprites in the scene drawn as a normal sprite (not sliced). |
| Find all GameObjects in the scene referencing a specific prefab. |
| Find meshes in the scene that have no Level of Detail (LOD) and a triangle count higher than 2000. |
| Find all assets used in a selected scene prefab. |
Provider filters
The Hierarchy search provider supports the following filters.
Components and properties
The syntax for components and properties in the Hierarchy search provider:
-
Use theprefix to search for a component. The prefix can require an exact match if you use
t, or a partial match if you use=.:h: t:Cameh: t=Camera -
Use theor
component.propertynotation to find properties with a specified value.p(component.property)h: Camera.Orthographic=trueh: p(Camera.Orthographic)=trueh: Orthographic=trueh: p(Orthographic)=true -
If a property is unique to a component, you don't have to specify the component in the query. For example, the following queries are equivalent if only the Camera component has a field of view property:
h: fieldofview=60h: Camera.fieldofview=60 -
Words in filters can't have spaces, so if a property or component name has spaces, remove them. For example,becomes
Field of view.fieldofview
Unity indexes properties according to their internal name, which might be different than the display name in the window. To search by property value, do one of the following:
Inspector
?
- Use the visual query builder, which uses the property's display name.
- Check the Inspector window in Debug mode to find the internal name of a property.
For more information about components and properties in the Hierarchy search provider, and how they differ from the Project search provider, refer to Introduction to searching your project and scenes.
Layers
Find GameObjects by their built-in or user-defined layer.
h: layer=<layer ID>
For example: Find all GameObjects in the Water layer, whose ID is :
4h: layer=4
The visual query builder shows all available layers, including the built-in ones. If you want to use a textual query, you can find the layer ID and name in the Tags & Layers window. For more information, refer to Layers.
Rendering Layers
Find GameObjects by their built-in or user-defined rendering layer.
h: renderinglayer:NameOfRenderingLayer
For example: Find all GameObjects in the rendering layer:
Defaulth: renderinglayer:Default
The visual query builder shows all available rendering layers, including the built-in ones. If you want to use a textual query, you can find the layer name in the Tags & Layers window. For more information, refer to Introduction to Rendering Layers in URP
Tags
Find GameObjects by their built-in or user-defined tag.
h: tag=<string>
For example, to find all GameObjects with the tag :
Playerh: tag=Player
The visual query builder shows all available tags, including the built-in ones. If you want to use a textual query, you can find the tags in the Tags & Layers window. For more information, refer to <!-Tags and Layers.]
Reference
Find GameObjects by the asset they reference.
Filter option | Query example | Description |
|---|---|---|
| Reference By Asset Expression | | This is a nested query. It finds GameObjects that reference the result of the search for |
| Reference By Instance ID (Number) | | Finds GameObjects that reference a component with the specified Instance ID. To see a component's instance IDs, set the Inspector window to Debug Mode. |
| Referencing Asset (ID, path, or name) | | Find GameObjects referencing an asset by its name, exact path, or |
| Referencing GameObject (ID, path, or name) | | Find GameObjects referencing another GameObject by its name, exact path, or |
If you don't know the asset's ID, use this filter as part of a visual query, where you're able to choose the referenced asset from a list. If you need a textual query, you can convert the visual query to a textual one. For more information, refer to Launch and use the search window.
To get an asset's exact path, right-click the asset in the Project window and select Copy Path.
Another way to find references is with the context (right-click) menu:
- Project window: right-click an asset and select Find References In Scene or Find References In Project.
- Hierarchy window: right-click a GameObject and select Find References In Scene.
- window: right-click a component and select Find References In Scene.Inspector
?
Missing
Find GameObjects that are missing references such as materials or scripts.
Available options:
- Any: Any missing reference.
- Asset: Missing asset reference.
- : Missing prefab reference.Prefab
?
- Script: Missing script reference.
h: missing:<option>
For example: Find all GameObjects in the scene that are missing a prefab reference:
h: missing:Prefab
Prefabs
Find prefabs or their GameObjects.
Filter | Query example | Description |
|---|---|---|
| Any | | Find any asset (Project search provider) or GameObject (Hierarchy search provider) that is part of a prefab. If you search for |
| Altered | | Find prefab instances or variants with overrides, including default overrides. |
| Asset | | Find prefab asset. |
| Base | | Find base prefabs. |
| Instance | | Find objects that are part of a prefab instance. |
| Model | | Find GameObjects that are part of a model prefab. |
| Modified | | Find GameObjects that are a prefab instance with overrides. |
| Non asset | | Find prefabs that aren't prefab asset. |
| Regular | | Find regular prefab instances or assets. |
| Root prefab | | Find prefabs that aren't children of other prefabs. |
| Top (root) | | Find top-level prefab roots. |
| Variant | | Find prefab variants (Project search provider) or GameObjects from a variant (Hierarchy search provider). |
For details on the different prefab options, refer to Prefabs.
Scene Filters
Find GameObjects based on properties that impact their behavior in the scene.
Filter | Query example | Description |
|---|---|---|
| Active | | Find all active GameObjects. |
| Child | | Fine all child GameObjects. |
| Components count | | Find GameObjects with more than five components. |
| Hidden | | Find all hidden GameObjects. |
| Instance ID | | Find GameObjects by the instance ID of their components. To display a component's instance IDs, set the Inspector window to Debug Mode. |
| Leaf | | Find GameObjects that don't have children. |
| Path | | Find GameObjects nested under the ChildGameObject. |
| Prefab | | Find all prefabs. |
| Root | | Find GameObjects that don't have a parent. |
| Static | | Find all static GameObjects. |
| Visible | | Find all visible GameObjects. |
| Volume size | | Find GameObjects whose volume (based on their Transform Scale values) is greater than 5. |
Custom Scene Filters
Find GameObjects by their serialised properties.
The available filters depend on the serialized properties in your project.
Fuzzy search
Use a fuzzy search to find items that are similar to your query, but not an exact match. For example, where the string's characters aren't in the same order, or have other characters between them.
Query example: To find two GameObjects, one called and one called :
scorescrh: +fuzzy scr
When using a visual query, the Fuzzy Search filter is part of the Options filter group.
Results
Search window tab: Hierarchy.
Actions
The context menu for the Hierarchy search provider includes the following actions:
Action | Description |
|---|---|
| Select | Open the GameObject in the Inspector window and Scene view. This is the default double-click action. To change the default action, refer to Preferences. |
| Open | Open the GameObject in the Project and Inspector windows. |
| Hide or Show | Toggle the visibility of the GameObject in the Scene view. |
Visual element references
Find visual element references in the scene with the filter. This filter matches GameObjects that have a visual element reference to a specific element in a UI Toolkit visual tree.
veRefFilter | Description |
|---|---|
| Matches any reference. |
| Matches references with an empty path and no panel renderer. |
| Matches references where the path doesn't resolve to an element or the PanelRenderer/VisualTreeAsset is missing. |
| Matches references with a partial path match. |
| Matches references with an exact path match. |