I’m using ‘Application.LoadLevelAsync’ to load my game level from my main menu.
But about 3 out of 5 tries, it will just … stop, and freeze! (This only happens when built and running on my iOS devices - doesn’t happen within the editor).
It doesn’t crash, nor is Xcode throwing any errors, it just simply stops, mainly at around 80% level loaded. Although my loading music is still playing.
Can anyone explain this?
This is my function thats called when loading a new scene:
function LaunchGame(players : String, game : String, table : String){
print("[MC] Launching Game!");
PlayerPrefs.SetInt("background_colour", backgroundRandom);
PlayerPrefs.SetString("player_type", players);
PlayerPrefs.SetString("game_type", game);
PlayerPrefs.SetString("table_type", null);
yield WaitForSeconds(1.5);
print("[MC] Loading...");
var async = Application.LoadLevelAsync(1);
while (!async.isDone) {
print ("%: " + async.progress);
yield;
}
}
Thanks.
I couldn’t find the problem exactly, but I personally think it gets stuck when trying to load the scene within the background and then once loaded, jump right into the new scene.
So what I did was made the scene load about 2 seconds after the Main Menu has loaded, but DON’T launch into it. I only launch into it when the user clicks play.
This benefits me in two ways:
-
My game never crashes during loading
-
When the player clicks play, the scene is much quicker to load in, as the majority of it has already loaded.
I do this by calling this function when I want to load the scene, but not launch it (so call it within Start)
var async : AsyncOperation;
function LoadGameInBackground(){
async = Application.LoadLevelAsync(1);
async.allowSceneActivation = false;
while(async.progress < 0.9){
print(async.progress + "%");
yield;
}
print("Level loaded in background - waiting for launch prompt");
}
Then when the user clicks play, this function is then called, which activates the scene:
function LaunchGame(players : String, game : String, table : String){
print("[MC - Launch] Saving game types");
PlayerPrefs.SetInt("background_colour", backgroundRandom);
PlayerPrefs.SetString("player_type", players); //solo, host, join, passngo
PlayerPrefs.SetString("game_type", game);
PlayerPrefs.SetString("table_type", null);
yield WaitForSeconds(0.5);
print("[MC - Launch Active] Activating new scene");
async.allowSceneActivation = true;
}