When does the LoadScene() function in Unity change the scene?

It's

 UnityEngine.SceneManagement.SceneManager.LoadScene("Gameplay");

and yes it does it "instantly" -- that is to say synchronously.

In other words, it "stops" at that line of code, waits until it loads the whole scene (even if that takes some seconds) and then the new scene begins.

Do not use the old command you mention in the question.

Note that Unity also has the ability to do async loading .. it "slowly loads the new scene in the background".

However: I encourage you to only use ordinary "LoadScene". All that matters is reliability and simplicity. Users simply don't mind if the machine just "stops" for a few seconds while a level loads.

(Every time I click "Netflix" on my TV, it takes some time for the TV to do that. Nobody cares - it is normal.)

But if you do want to load in the background, here's how...

public void LaunchGameRunWith(string levelCode, int stars, int diamonds)
    {
    .. analytics
    StartCoroutine(_game( levelCode, superBombs, hearts));
    }

private IEnumerator _game(string levelFileName, int stars, int diamonds)
    {
    // first, add some fake delay so it looks impressive on
    // ordinary modern machines made after 1960
    yield return new WaitForSeconds(1.5f);

    AsyncOperation ao;
    ao = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync("Gameplay");

    // here's exactly how you wait for it to load:
    while (!ao.isDone)
        {
        Debug.Log("loading " +ao.progress.ToString("n2"));
        yield return null;
        }

    // here's a confusing issue. in the new scene you have to have
    // some sort of script that controls things, perhaps "NewLap"
    NewLap newLap = Object.FindObjectOfType< NewLap >();
    Gameplay gameplay = Object.FindObjectOfType<Gameplay>();

    // this is precisely how you conceptually pass info from
    // say your "main menu scene" to "actual gameplay"...
    newLap.StarLevel = stars;
    newLap.DiamondTime = diamonds;

    newLap.ActuallyBeginRunWithLevel(levelFileName);
    }

Note: that script answers the question of how you pass information "from your main menu" when the player hits play "on to the actual game play scene".

Tags:

C#

Unity3D

Unity5