How to instantiate prefabs in an unloaded (or just loaded) scene?

So I’m very new to Unity3D and just recently started work on my first, true, large-scale game. Thanks to the wonderful tutorial at BugZergArcade, my time has been very well spent and I’ve been learning quickly.

To avoid the need for artists and still allow for unlimited gameplay, I wished to implement procedural level generation. This is where the tutorials fell short. They don’t have anything on world generation.

When I looked into how to make a script run at start-up the official recommendation seems to be to have an empty GameObject in the world, then attach the script to this. I foresee one of two possible problems with this, however.

  1. If the scripts run in parallel then the player may be able to move around or fall through the world before it’s finished generating
  2. If the scripts run in series then I won’t be able to update the GUI as the world generates, which means no “loading bars”

Does anyone have a solution for this, or are my two worries simply unfounded? Ultimately I want the final effect to be: User starts game, user sees main menu, user hits play, user sees a loading screen, user is placed in a random world.

Can use a coroutine to spread out world generation over a few frames. Do about 1/4 second’s worth of work, then yield for a frame. Sort of an odd system. The trick is that nothing happens while you are doing work. No frames, no drawing, no timer changing. So each frame happens when you yield.

For the player, just give the player a Paused variable. You’ll probably have one anyway, for menus (or the Pause key?) Set to true when done making the level. Or you could spawn the player last (most people would have the players pre-spawned.)