Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
Matthewsre's avatar
Matthewsre
Honored Guest
12 years ago

Loading Scenes with dynamic level generation

I asked this question on Unity Answers, but it seems like it might be a while before it is approved and I had a goal of finishing this up this weekend (closing in fast) so I will see if I can get any information here.

I have a game I have been working on for Oculus Rift and am randomly generating the level (cloning prefabs, terrain tiles, etc). Loading currently takes about 30 seconds and once everything is loaded things run smoothly with a decent framerate.

Sorry in advance if there are answers out there already, but everything I could find was using premade scenes and not using the start method to instantiate everything randomly (which is a key feature of my game).

First attempt I had everything in the start method. I tried using LoadLevelAsync (Yes I am using Pro) and backgroundLoadingPriority and that was not working as the Start would not run until I switched to the loaded Scene.

Second attempt I tried loading additive, but since everything is triggered with the start menu it still tanked my framerate to .1 FPS.

Third attempt I created a loading screen in the scene with no transition and I tried loading everything in the update. In the update I have an if/else if checking whether or not processes have completed (they flip the bool when done) and then kick off the next task (repeat until all fla).

Fourth attempt I tried the same thing using Coroutines to try and squeak out a better framerate and no dice.

I am sure there is a good solution out there for this but have yet to find it.

Here is my current code in the update so you cant see the third and fourth I am doing

    void Update () {

if (_isLoadedGame)
{
return;
}

if (!_isLoadedTerrain || !_isLoadedTerrainStarted)
{
if (!_isLoadedTerrainStarted)
{
SetLoadingText("Generating Randomized Terrain...");
//StartCoroutine("LoadTerrainAsync");
_isLoadedTerrainStarted = true;
Invoke("LoadTerrain", .2f);
}
}
else if (!_isLoadedEnvironment || !_isLoadedEnvironmentStarted)
{
if (!_isLoadedEnvironmentStarted)
{
SetLoadingText("Randomizing Environment on Terrain...");
//StartCoroutine("LoadEnvironmentAsync");
_isLoadedEnvironmentStarted = true;
Invoke("LoadEnvironment", .2f);
}
}
else if (!_isLoadedPathfinding || !_isLoadedPathfindingStarted)
{
if (!_isLoadedPathfindingStarted)
{
SetLoadingText("Scanning for Pathfinding...");
//StartCoroutine("LoadPathfindingAsync");
_isLoadedPathfindingStarted = true;
Invoke("LoadPathfinding", .2f);
}
}
else if (!_isLoadedOptimizations || !_isLoadedOptimizationsStarted)
{
if (!_isLoadedOptimizationsStarted)
{
SetLoadingText("Optimizing Environment...");
//StartCoroutine("OptimizeEnvironmentAsync");
_isLoadedOptimizationsStarted = true;
Invoke("OptimizeEnvironment", .2f);
}
}
else if (!_isLoadedGame)
{
LoadGame();
_isLoadedGame = true;
}
}


Current solution works for updating loading screen text and locking its position on the screen with no Oculus movement, but I would like to give the user some visual feedback, animation, or let them look around with the Oculus while waiting for a background thread to load. Any help would be greatly appreciated :)

So far the most useful information I have found was here:
viewtopic.php?f=37&t=9702