Problems with LoadLevelAsync and Android pro.

I have a problem when the program load scenes. Sometimes works and sometimes not.
I have this sequence

Scene1 —> Scene2 --async–> Scene3 —> Scene1 —> Scene2 --async–> Scene3

Sometimes the first LoadLevelAsync works fine and the second not.
Scene3 is the game, and it has an scenario, characters, a lot of stuff. When I back from that scene to scene1 and then on scene2 call LoadLevelAsync, always freezes. I dont know why, because, previously the first asyncload worked fine.

The code is this:

using UnityEngine;
using System.Collections;

public class LevelLoader : MonoBehaviour {

	static public string LevelToLoad="Menu";
	public AsyncOperation async = null; 
	private float progreso = 0.0f;
	private bool ejecutado = false;

	IEnumerator Start() {
		async = Application.LoadLevelAsync(LevelToLoad);
		async.allowSceneActivation = false;
		yield return async;
	}

	void FixedUpdate () {
		if (async != null){
			progreso = async.progress;
			transform.localScale = new Vector3(progreso, 1, 1);
			if (progreso>=0.9f) {
				transform.localScale = new Vector3(1, 1, 1);
				if(!ejecutado){
					ejecutado = true;
					Invoke("LoadLevel",1f);
				}
			}
		}
	}

	void LoadLevel(){
		async.allowSceneActivation = true;
	}

}

And the call to execute this script is this:

		LevelLoader.LevelToLoad = "Menu";
		Application.LoadLevel("LevelLoader");

Does anybody had problems with LoadLevelAsync on Android?

Regards and sorry, I have a better spanish :stuck_out_tongue:

Try changing LoadLevelAsync to LoadLevelAdditiveAsync.

I’ve had problems too using ‘async.allowSceneActivation = false’ to delay start using LoadLevelAsync with many freezes and crashes.

When you set your ‘ejecutado’ to true then just call Destroy(this.gameObject, 1f) so that it will be destroyed when after everything has been successfully loaded. Make sure you parent everything in the level loading scene to this object so that everything is destroyed with it.
When you set async.allowSceneActivation back to true it finishes the last part of the load (the 0.1f left over.) so there’ll still be a delay. If you destroy immediately then you may get a flicker as a camera will be destroyed before a new one is shown depending on how large the scene is.

Hope it’s sorted.