How do I loop through a folder of ScriptableObjects and get the information from all of them?

I have a file (currently with only one ScriptableObject but I will eventually add more which is why I need this) and I have another script which I want to have loop through that file and look at the information of all of the SO scripts. Here is the script for each of the SO scripts in the file:

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

[CreateAssetMenu(menuName ="Add recipie")]
public class craftingRecipies : ScriptableObject
{
    public string[] itemsList;
    public int[] itemsNum;

    public string[] outputList;
    public int[] outputNum;
}

How would I go about looping through the File and checking all of this info?
Where possible, the better the performance the better but at this point in time performance is not the main issue so I am not that fussy

Collections / groups of ScriptableObjects can either be dragged into an array / list type variable or even loaded en-masse with calls such as Resources.LoadAll<T>().

Then you just iterate each one, and from the look of your data above, iterate each items list and items num within it.

You may wish to think ahead of the curve and provide ScriptableObject “Ingredients” and then make ScriptableObject “outputs” or “products” rather than all that strings and numbers stuff bare like that.

Also, you may wish to get your plural / singular correct: You name it craftingRecipies but I think it is really just ONE recipe, right? So it should be CraftingRecipe

And here’s a bunch of them (“recipes” is the correct pluralization of “recipe”):

public CraftingRecipe[] AllRecipes;

to load at runtime (see Resources.LoadAll() rules in documentation!!!):

CraftingRecipes[] LoadedRecipes = Resources.LoadAll<CraftingRecipe>( "CraftingRecipesFolder/");

Fun fact: if you say “recipe” out loud enough time or type it enough times, it starts to look really really really weird as a word.

1 Like

because the file is filled with c# scripts, in this case the Objects[ ] would have to be a script[ ] of sorts. is there way to do a list/array of scripts?

That’s not really how it’s done. You might want to review how basic ScriptableObjects work and how you define one class and then make as many instances of it as you want as asset files on disk.

It’s kinda like this:
https://www.youtube.com/watch?v=M89adxabzPk

Plenty more of where that comes from… see what Youtube suggests for you.