Get new Camera after Application.loadLevel

I have an RPC function, that is passed an array of names by the server. It should change the scene to allow character selection. Changing the scene does work, however, I can’t seem to get the right camera object (which would have the character creation GUI attached).

	Application.LoadLevel("ChooseCharacter");
	Debug.Log(Camera.current.name);
	ChooseCharacterGUI gui = Camera.current.GetComponent<ChooseCharacterGUI>();
	gui.gameController = this;

Line 2 gives me “Main Camera Login” which indicates the camera that was active before Application.LoadLevel. Line 4 breaks my app as the gui reference is null.

Guess I have to wait a frame or something similar?

Yeah the level won’t have finished being loaded yet.

If you put use an async load and wait for it to finish that will work:

IEnumerator LoadNewLevel(string LevelName)
{
		AsyncOperation async = Application.LoadLevelAsync(LevelName);
		yield return async;
		ChooseCharacterGUI gui = Camera.current.GetComponent<ChooseCharacterGUI>();
		gui.gameController = this;
}