How can I make a loading screen with LoadSceneAsync

Hello everyone, I have three scenes in my project - one for the main menu, one for the map and the game itself and one for the loading screen between the game and the main menu. I’m trying to make it so when I hit the button Play on the main menu, the scene switches to the loading screen and a script attached to the camera immediately starts loading the scene with the map with LoadSceneAsync.

When I try the game, I expect to switch to the loading screen scene after i hit the button Play on the main menu. Then the loading screen scene should stay on until the playable scene with the map loads and switches.

Unfortunately, I get completely different results - after I hit Play, the game freezes (as it does with the normal LoadScene function) until the scene with the map loads. Then it switches to the loading screen scene for a second and then to the scene with the map.

This is the code that is compiled when the button Play on the main menu is pressed:

    public void Play()
    {
        SceneManager.LoadScene("LoadingScreen");
        PresenceManager.UpdatePresence(detail: "Exploring Ancient Greece",start: System.DateTimeOffset.Now.ToUnixTimeSeconds());
        Cursor.visible = false;
    }

This is the script attached to the camera in the loading screen scene which responds for loading the map scene with LoadSceneAsync:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class LoadingLevel : MonoBehaviour
{
    void Start()
    {
        SceneManager.LoadSceneAsync("SampleLevel");
    }
}

Do you have any ideas on what I am doing wrong and how to fix it. Any help would be appreciated. :slight_smile:

LoadSceneAsync is a little more complicated I think to get right, here is a try:

AsyncOperation asyncLoad;
bool bLoadDone;
IEnumerator LoadAsyncScene()
{
    asyncLoad = SceneManager.LoadSceneAsync("SampleLevel", LoadSceneMode.Single);
    asyncLoad.allowSceneActivation = false;
    //wait until the asynchronous scene fully loads
    while (!asyncLoad.isDone)
    {
        //scene has loaded as much as possible,
        // the last 10% can't be multi-threaded
        if (asyncLoad.progress >= 0.9f)
        {
            asyncLoad.allowSceneActivation = true;
        }
        yield return null;
    }
    bLoadDone = asyncLoad.isDone;
}

bLoadDone = false;
StartCoroutine(LoadAsyncScene()); //call to begin loading scene
//wait for bLoadDone==true

I think you should have the loading screen implemented in the Menu-scene, hide the menu, then begin the LoadAsyncScene, then show the progress. Fewer scenes is a good thing in my view.


But you will not get totally smooth framerate during scene transitions/loading… It’s the way things are, there will be freezes.

Hey, just implemented that code into Unity but the game still freezes and stays unresponsive until the scene activation phase begins. It’s clear to me the LoadSceneAsync still won’t get me smooth FPS during transitions but not freezing the whole scene is totally enough for me. @rh_galaxy

Do you test it in the editor, or in a standalone build?
The editor will produce very different results when it comes to scene loads.