AssetDatabase.FindAssets, how to use with namespaces?

I try to find my ScriptableObjects with AssetDatabase.FindAssets(filter, folders).

They are found, as long as they are not in a namespace. If I use a namespace, they aren’t found anymore, if the type is used as filter.
I don’t really understand how the filter is working, so I tried it with brute force. But that approach wasn’t successful at all.

ScriptableObject, with namespace:

using UnityEngine;

namespace Franz.Item
{
    public class ItemDefinition : ScriptableObject
    {
        public string ItemName = "Test";
    }
}

ScriptableObject, without namespace:

using UnityEngine;

public class ItemDefinition : ScriptableObject
{
    public string ItemName = "Test";
}

This is what I tried to find the ScriptableObjects:

    var AssetDirectory = "Assets/Items";
    var assetPaths1 = AssetDatabase.FindAssets("*", new[] { AssetDirectory });

    var assetPaths2 = AssetDatabase.FindAssets("t:ItemDefinition", new[] { AssetDirectory });
    var assetPaths3 = AssetDatabase.FindAssets("t:Item.ItemDefinition", new[] { AssetDirectory });
    var assetPaths4 = AssetDatabase.FindAssets("t:Franz.Item.ItemDefinition", new[] { AssetDirectory });
    var assetPaths5 = AssetDatabase.FindAssets("t:" + typeof(ItemDefinition), new[] { AssetDirectory });

    var assetPaths2A = AssetDatabase.FindAssets("t:'ItemDefinition'", new[] { AssetDirectory });
    var assetPaths3A = AssetDatabase.FindAssets("t:'Item.ItemDefinition'", new[] { AssetDirectory });
    var assetPaths4A = AssetDatabase.FindAssets("t:'Franz.Item.ItemDefinition'", new[] { AssetDirectory });
    var assetPaths5A = AssetDatabase.FindAssets("t:'" + typeof(ItemDefinition) + "'", new[] { AssetDirectory });

    var assetPaths2B = AssetDatabase.FindAssets("t:\"ItemDefinition\"", new[] { AssetDirectory });
    var assetPaths3B = AssetDatabase.FindAssets("t:\"Item.ItemDefinition\"", new[] { AssetDirectory });
    var assetPaths4B = AssetDatabase.FindAssets("t:\"Franz.Item.ItemDefinition\"", new[] { AssetDirectory });
    var assetPaths5B = AssetDatabase.FindAssets("t:\"" + typeof(ItemDefinition) + "\"", new[] { AssetDirectory });
  1. Test scenario: ScriptableObject with namespace

assetPaths1 found the ScriptableObjects.

The other filters returned 0 results.

  1. Test scenario: ScriptableObject without namespace

assetPaths1, 2, 3, 4 and5 found the ScriptableObjects.

The filters with A and B suffix returned 0 results.

I can imagine why assetPaths1 could find results in both scenarios.

I can imagine why assetPaths2 could find results in the 2. scenario.

I don’t understand why assetPaths3, 4 and 5 found results in the 2. scenario.

From the documentation:

The filter string can contain search data for: names, asset labels and types (class names).

So my filter with “type” is actually a filter with “class name”?

But what happens with the dots?

And why doesn’t it work with namespaces? The class name didn’t change.

My workaround for now: Hoping that I don’t put something in the Items folder, that is not an ItemDefinition.

I ran into the same problem, for nested namespace the FindAssets couldn’t find any object, after digging a little bit and this is how I fixed it,

I renamed all scriptable object to exactly the class name, by doing this, Unity could find them again, then i change the name back to original name and it still working.

I have no idea what’s going on but this trick fix the problem, Just thought it might help someone.