Map prefabs to names for external level loading

I’m basically allowing people to create their own maps and etc, however I’m stuck on a more automated solution to my problem. Basically, I have a file with pos|rotation|name and I need to basically map the name to the prefabs so they can be instantiated in the scene at runtime.

I thought about having an array like this:

MapObject[] Objects = {}

which is basically defined as:

class MapObject
{
    GameObject LevelObject;
    string Name; 
}

however this would require me to maintain the array of objects so it could actually lookup the objects. So I’m basically wondering if anyone has a better idea on how this can be more automated so I don’t have to keep adding objects to an array each time I add a new one.

A gameObject has a name, which is a string. You can modify it if necessary.

The game objects aren’t in the scene by default, they’re spawned if they’re needed for the level.

There’s always a tag. None of us really knows what you are up to though, so it’s pretty hard to give specific advice. I have considered your first approach but haven’t tried it yet. The trick would be to have a simple and automatic way of updating the list as the game changed. Since yours seems to do with object creation, it doesn’t seem like it would be very hard. If the object moves, and you have to keep track of that, it gets a little harder. Otherwise you just write your own function for creating objects that both creates and adds to the list. So, you basically create your own static helper class.

Put all your prefabs in a Resources folder, store the names of the prefabs in your map file, and use Resources.Load to load them.

Thanks, I knew it would be simple enough.