[Solved] Is AssetDatabase.FindAssets broken in 2017.3.1?

Hi everyone,

I am trying to use AssetDatabase.FindAssets to find a script named “TestBehaviour” by it’s type. It seems that searching for “t:MonoScript” works, but I cannot find anything more detailed than that. Here is the code:

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

public class TestBehaviour : MonoBehaviour {
    [MenuItem("Assets/Find TestBehaviour")]
    private static void ReplaceReferencesInProject()
    {
        string[] guidsFound = AssetDatabase.FindAssets("t:TestBehaviour", null);
        Debug.Log(guidsFound.Length);
    }
}

This prints “0” to the debug log. Am I using this wrong or is it broken?

I’m not aware of any issues. Can you share an example project?

1 Like

Sure. Here ya go. It’s just a new project with a single script in it (the one above). Right click the script in the editor and click “Find TestBehaviour”. You will see a “0” gets printed to the console.

3443896–272570–TestFindAssets.zip (2.29 MB)

1 Like

I see the problem. You are searching for an asset of type TestBehaviour. In the project, it is an asset of type Script.
If you wanted to find a script with a particular name you would do AssetDatabase.FindAssets("t:Script TestBehaviour")
This is intentional. If you had instances of your script saved as assets then this would work, say for example ScriptableObject assets.

1 Like

Hey, thanks a lot! So I was using it wrong. My goal was to find scripts in the project as well as scripts in DLL’s that possess that type, and this works for both it seems. Thanks again!

1 Like