Skip to content

RoyTheunissen/GUID-Search

Repository files navigation

Roy Theunissen License: MIT GitHub Follow globe bluesky youtube tiktok

Sometimes you really need to find all the places where an asset is being referenced, and Unity's own search solutions are too unreliable for this.

About the Project

Let's say you removed a script from your game, and you want to ensure that it's also removed from scenes/prefabs. You might be inclined to use Right Click -> Find References in Project, which opens a Search window which will be thinking and processing for a very, very long time and then will then output some results.

In practice I've found that it won't find usages in scenes unless those scenes happen to be open, and its track record is spotty with prefabs, too.

In other words: if you're doing an important refactor and must know all the places an asset's referenced, Unity Search will not suffice.

But every asset has a GUID, so you could simply search the contents of assets for that GUID. In fact, you could do it in Notepad++ pretty easily:

  • Go to the asset in question in Unity
  • Right Click -> Show in Explorer
  • Go to the asset in question's .meta file
  • Copy the GUID
  • Press CTRL+Shift+F or go to to Search > Find in Files
  • Search for the specified GUID in files with pattern *.unity *.prefab in your project's Assets folder.
  • This will think only for a few seconds and then output a list of every reference to that asset.
  • You can then search for that asset by name in Unity

This is a very robust approach, but of course you have to leave the editor for this, and there's a lot of manual labour involved. GUID Search is essentially just a nice GUI for the above mentioned workflow:

image

When doing important refactors, this tool is simple, fast, and thorough enough to get the job done.

It is guaranteed to find every possible reference.

Use Cases

  • You want to remove a script, but before you do you want to check where it's being used.
  • There's a problem with a shader, so you want to find all the materials that use that shader.
  • You're cleaning up a folder called Archived but you want to check that the Scriptable Object inside is genuinely not being used any more.
  • Etc.

Getting Started

  • Open the GUID Search window via Window > Search > GUID Search image

  • Drag in an asset in the Asset to find field.

  • The GUID for the asset in question will appear.

  • Specify the types of files to search in.

  • Specify the folder to search in.

  • Press Search.

  • Observe how all the assets that reference the specified asset are listed, and you can click on them to open them.

image

Pictured: A script that is referenced inside a specific scene will be found even if that scene is not open, something that Unity's own Search solution does not seem to do.

Caveats

  • If you have a reference to an asset in a script, then remove that field from the script, the assets that had the reference will continue to have the reference until you modify and save the asset. You can see this happening in your version control software. It makes sense if you think about it: if you remove a field from a script you don't see Unity start a lengthy process of purging all the references of that field from its prefabs and scenes, polluting your working copy with a lot of changes. This also means that if you have any such leftover references lying around, GUID Search will find those as well. GUID Search will find everything, and it's up to you to filter out such false positives.
  • If you have a reference somewhere deep in a complicated prefab or scene, GUID Search is not able to tell you where inside that complicated prefab or scene. It's then up to you to go looking for the exact reference.

Feature Wishlist

  • Some (optional?) way to check if a reference is from a script, and then to check if that script does indeed still contain the specified field. If not, we could filter out search results for references that are not in use.
  • Some (optional?) way to locate the exact location of a reference inside of a prefab or script. This might be tricky, we may have to parse the asset a bit. There's also the question of how to present this in the GUI.

Compatibility

This system was developed for Unity 2022, it's recommended that you use it in Unity 2022 or upwards. It's been tested in Unity 6 as well and seems to work the same there.

If you use an older version of Unity and are running into trouble, feel free to reach out and I'll see what I can do.

The GUI was developed with UI Toolkit and the functionality is pretty basic, so this tool will likely work across a wide range of Unity versions.

Installation

Package Manager

Go to Edit > Project Settings > Package Manager. Under 'Scoped Registries' make sure there is an OpenUPM entry.

If you don't have one: click the + button and enter the following values:

  • Name: OpenUPM
  • URL: https://package.openupm.com

Then under 'Scope(s)' press the + button and add com.roytheunissen.

It should look something like this:
image


All of my packages will now be available to you in the Package Manager in the 'My Registries' section and can be installed from there.

Git Submodule

You can check out this repository as a submodule into your project's Assets folder. This is recommended if you intend to contribute to the repository yourself.

OpenUPM

The package is available on the openupm registry. It's recommended to install it via openupm-cli.

openupm add com.roytheunissen.guid-search

Manifest

You can also install via git URL by adding this entry in your manifest.json (make sure to end with a comma if you're adding this at the top)

"com.roytheunissen.guid-search": "https://github.com/RoyTheunissen/GUID-Search.git"

Unity Package Manager

From Window->Package Manager, click on the + sign and Add from git:

https://github.com/RoyTheunissen/GUID-Search.git

Contact

Roy Theunissen

[email protected]

About

Utility for finding asset references by GUID. Fast and thorough.

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Packages

No packages published

Languages