[While Statement] From Scene To Scene!

All I wanted to do is to transfer some values from one scene to another and I don’t want to save them into an external file (at least for now,) therefore I use DontDestroyOnLoad(gameObject) for a Game object that holds these values. So the code is something like this:

public void LoadLevel(int id)
	{
                        Application.LoadLevel(id);
			
			StartCoroutine("CreateGameController");
	}


IEnumerator CreateGameController()
	{
		while (Application.isLoadingLevel)
			yield return new WaitForSeconds(0.1f);
		
		if (GameController)
			Instantiate(GameController, Vector3.zero, Quaternion.identity);
	}

When I test on Unity remote it works perfectly. And the [Instantiate statement] does its work once the level is loaded. But when I deploy it into the iPhone it get stuck when the level is loaded and the [Instantiate statement] does not work! At the beginning I thought it might be [While statement] is taking a nice nap there so I decided to remove it and replace it with yiled statement but nothing change really … Any idea whats going?

I think you need

Application.LoadLevelAsync?

Thx oliverdb … but even with the LoadLevelAsync I got the same result! … is there any other suggestion?

I am not sure what is going on, but you could user playerprefs to store values instead of not destroying.

yea, I could do it with playerprefs but for now I just want it like that because later on I’ll use the non-destroyed object as well in the next loaded level. I believe it should work well since i tested it in the Unity remote and everything was going well!

well I make my loader object an DontDestroyOnLoad(gameObject) and then my game-scene ask for the object when they get the MonoBehaviour.OnLevelWasLoaded event. So the loader objects stores the data.

I have my game controlling object loaded on startup and then never destroy it. All my scenes are loaded additively async after this, and I destroy objects when they are not needed.

e.g.

Load MAIN (persistent).
Load MAIN MENU
.
.
.
Destroy MAIN MENU root object
Load GARAGE
Load CAR
.
.
.
Destroy GARAGE root object
Load RACE TRACK
.
.
.
Destroy CAR root object
Destroy RACE TRACK root object
Load MAIN MENU
.
.