Search code examples
asynchronousunity-game-enginescene

Unity - Wait in MainMenu till Scene is completely loaded


I have a little problem with my main menu in Unity.

If I press the "Play" Button, it starts the game how I want it to.

The problem is, that my scene "Lights" are not completely loaded. (I have a lot of effects in it). So the scene is loaded, but everything is dark, completely without the lights:

My scene when run: no lights

I tried it with asynchronous "LoadSceneAsync", like so:

public void LoadByIndex(int sceneIndex) {
    StartCoroutine(LoadNewScene(sceneIndex));
}

IEnumerator LoadNewScene(int sceneNumber) {
    AsyncOperation async = SceneManager.LoadSceneAsync(sceneNumber);

    while (!async.isDone) {
        Debug.Log("hello");

        yield return 0;
    }  
}

Solution

  • Ok i got it.

    The problem was the Auto-Light-Baking.

    Just go to Window > Lighting > Settings > Scene

    And then scroll to the bottom and uncheck the "Auto Generate" for "Generate Lighting"