Resources.LoadAllOfType With ScriptableObjects?

I am trying to add every ScriptableObject i find to a list. The ScriptableObject is called “Items”

I already declared itemsList

Here’s my code:

 public void loadAllItemsInList() {

     foreach (Items item in Resources.FindObjectsOfTypeAll(typeof(Items)) as Items[]) {
             Debug.Log (item.itemName);

It seems like it should work. But it doesn’t. It just returns an error showing me where i declared my Foreach. And. Saying “Object reference not set to an instance of an object”. No clue how to fix this

You cannot cast an Object[] to an Items[]. What you can do is use LINQ to convert the Objects into Items:

foreach (Items item in Resources.FindObjectsOfTypeAll(typeof(Items)).Cast<Items>())