Reliable way to get all ScriptableObjects of given type at runtime

So I have a situation where I need to cache off all scriptable objects of a particular type at run time.

I thought the solution would be to put them into a resource folder and use this command:

foreach( DurableEntry d in Resources.FindObjectsOfTypeAll(typeof(DurableEntry)) as DurableEntry[])
{
    MyCache.Add(d);
}

This proves to be very unreliable however. I had 4 of these in the resource folder and sometimes this will find 1 of them. Sometimes 2. Sometimes all 4. Whats going on there?

My fallback is to hand drag the items into the MyCache list. But thats not what I wanted to do.

Any ideas?

I figured out a different solution:

DurableEntry[] d = Resources.LoadAll<DurableEntry>("Durables");

I then put the array of content into a dictionary with a string key for easy lookup.

7 Likes