Trouble With AssetDatabase.FindAssets Exact Match

I know AssetDatabase.FindAssets() can be used to search a subsection of the file name, but is it possible to search Assets by their full name only?
Like if I have 3 assets 1011.asset, 1012.asset, and 10111.asset
And how to make sure AssetDatabase.FindAssets(“1011”) would only return the first asset which is 1011.asset, but both 1011.asset and 10111.asset?

You will find the answers here: Unity - Manual: Unity Search
Specifically exact and partial matching are described here: Unity - Manual: Search query operators

If the search result provides you with more results than you expect and the search operators cannot accomodate for this, you can still filter out the result set using your own filter (ie by using LINQ).

If feel like the operators are partially broken in Unity 2022.3.2f1
Trying to search a file with “exactName” with the following queries fails
!exactName
or
p:!exactName
or
name=exactName

4 Likes

Pardon the necro, but I’m also having trouble getting the exactName to work. Been testing search strings in the editor and !exactName doesn’t return my object. But exactName does.

I’m on Unity 6000.0.26f1.

There are two search engines in Unity: The new “Unity Search” one, for which CodeSmile linked the documentation above, and the old “Classic” or “Legacy” search. For the UI, you can choose which one to use in Preferences → Search → Search Engines.

However, AssetDatabase.FindAsset always uses the classic/legacy search. The query operators in the “Unity Search” documentation don’t work and only the ones listed in the AssetDatabase.FindAssets documentation do.

There’s no exact search in the legacy search engine. You’ll either have to do the partial search and then pick the exact match from the results yourself or manually search the file system using plain C#.

1 Like

Ah thanks for the information. Pity the new Unity Search doesn’t work with AssetDatabase.FindAssets. :confused:

The new search has been built into the editor since Unity 2021, so you can use and rely on it (previously it was in a separate package as Quick Search):

But, for simple queries, the old search will be much easier to use. With the new one, you have to make sure it’s configured for your needs and all the queries are executed asynchronously.

1 Like