how to populate a list of gameobjects from a folder

Im not sure the best way to do this.

basically i’d like to have an editor where a GUI element has a list of objects you can spawn

but if i decide later to add a new object you can spawn i dont want it to be a huge pain.

So what i’d like to do is basically have code where i have a gameobject list variable
and add every object in a folder.

That way later when i want to add a new object I just drop the object into a prefab spawn folder and the code automagically adds it to the list of spawnable objects in the GUI.

So basically when i write

List MyList;

MyList.add(x);

how can i make x iterate through objects in a folder.

is there some kind of way to do

foreach (gameobject in “directory”)

For this type of functionality you need to use the Resources folder.

Make an editor script that creates a menu item which, when clicked, adds all objects in a folder whatever script you want. That way you only need to click a button when you want to update the list. The benefit of this is that you’re assets are not in the resources folder, and you can define differences in your task by creating several menu items that behave differently when you need it to.