Load a lot of Prefab on start

I have a sort of tilebased world. Not real tiles, just a LOT of objects put into a matrix kinda grid.

I am looking for good ideas of how to load these into GameObjects without having to code/copy-paste an extra line of GameObject.Resource.Load(“xyz”) for each time our artist designs a new object for ground, walls, obstracles, bonus-items etc.

I was thinking of loading all resources into an array og GameObjects, but then I need to figure out which goList[xyz] is what Prefab.

Reason is that the map/world is build up from loading levels from a webserver, so we get values/codes for which tile/prefab to init where. Multiple initations of same prefab on a world map.

Note: We currently use the Indie/free edition, so Assetsbundle is not an option. Once our game experience with Unity3D gets big enough and we are earning money this WILL be our main priority, but right now we have to stick with the Indie version.

An array (or multiple) is the way to go, so the artist can just drag it in. Rather than making it an array of GameObject, make it an array of (say) Info, which you make as a very simple script like:

var name : String;

if needed, add other stuff:

enum Category { Rock, Tree, ....... }
var category : Category;

The artist then adds an Info to the prefab and drags it into the array.

Alternatively, make it an array of struct like this:

class Info {
    var name : String;
    var prefab : GameObject;
    ...
}

The artist then adds an element to the array and fills out the details, including dragging in the plain GameObject prefab.

Either style is pretty comfortable for both you and the asset artist.

Also note that using Resource severely limits the value of incremental/streamed level loading, since all Resources are effectively built into level 0 - I.e. nothing can start until they are all loaded. In general, Resources are dangerous for web deployed games (the one thing I hate about the Detonator framework is its excessive use of Resources, which immediately bloat your game even if you don’t use the associated explosion types).

I found a way last night.

First I make a static/global array of GameObjects:

// notice its the generic Object and not GameObject! 
public Object[] models; 

Inside init code, like Start or whereever, I place this one

models = Resources.LoadAll("Models", typeof(GameObject));

Explanation:

Now I have a complete list of all imported models within the Models folder in Assets \ Ressources \ Models \

Btw. The Resources.LoadAll, returns a Object array, and I haven’t been able to typecast it into GameObject, but this works fine(?)

Test it:

for (int cnt=0; cnt< models.Length; cnt++)
{
   // lets iterate through them and show their names
   Debug.Log("model #"+ cnt + " is: " + models[cnt].name);
}

Usage:

Whenever you need them dynamically on the scene, you can run through the models array, either keep the index of the ones you need most or search by name.

Then instantiate them as needed:

int spawn = 52; // if loaded object #52 is your wanted object
GameObject go = (GameObject) Instantiate( models[spawn], 
                 new Vector3(xpos, ypos, zpos) , Quaternion.identity);

From here you can do to the go object what you need. Such as parent transform, movement, assign components etc.

Why do it this way?

As many of our levels are dynamically generated, we dont use the Unity3D editor for levelediting.

We build a LOAD of .fbx files from Blender or other 3D utils and the artists do not use Unity3D for placement and we just have a large folder + our own assetmanagement server/database.

When the artist registrates the .fbx within our server, we need to be able to pull these into the game to place on the levels too. This makes it possible for us to code our own custom level/prefab editor and keep our growing structure outside the Unity3D editor.