- Home /
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?
Answer by kalvinlyle · May 12, 2012 at 04:05 PM
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;
}
Thanks for the hint. Is there also a way without it? I just started learning unity and i don't have Unity Pro, yet. Asynch is Pro only.
Your answer

Follow this Question
Related Questions
Losing reference to the camera after loading new scene 0 Answers
Why my Camera is getting Duplicated? 0 Answers
How to make camera position relative to a specific target. 1 Answer
2 questions: camera change and a question about using && 2 Answers
Continue playing sound effect on camera after LoadScene 1 Answer