So based on @ SohailBukhari suggestion, I came up with a really good solution. Yes locking the inspector and dragging a bunch of objects into the list was a great simple solution, but I locked onto the idea of using the Resources folder. After some research, I found some useful things. Firstly, this code achieves it:
PrefabUID enemies = Resources.LoadAll<PrefabUID>("");
In this case, PrefabUID is a script I have attached to a GameObject stored in the Resources folder. That one line of code will get all of the GameObjects with that script attached in my Resources folder and sub folders. That’s the quick answer.
For anyone else interested in looking at this in the future, the Resources folder is where you put game assets that you always want included in the final project. Otherwise, prefabs and assets that are not in a scene anywherearen’t included in a build project (or probably testing at runtime in the editor either). So in other words, if you have prefabs you want to be able to access in code at any time, regardless of if they are in a scene or not, you should put them in a special folder called Resources.
If you put some GameObjects in the Resources folder, you can use the function I just did:
PrefabUID enemies = Resources.LoadAll<SomeType>("");
Resources.LoadAll() will load everything in the resources folder of the specified type, in this case, SomeType. You could set it to GameObject, Material to get all materials, a script or whatever you want.
There are other useful functions in Resources which you can read the documentation for here. Don’t be daunted, it’s actually really simple when you try it. The two others I’ve used are:
Which will load the asset with that name, or:
Which, if you have sub folders, will load all of the assets in the specified sub folder. I assume if you leave it blank it might load everything in the resources folder - or give you an error.
I have found Resources.FindObjectsOfTypeAll to be unreliable, so I wouldn’t recommend it. LoadAll does the same thing for what we want to achieve here.