Render Canvas Before LoadScene OnClick

Hi everyone,

I am working on a level loader script and have run into an issue here I can’t seem to find any info on. Bottom line is I just want to activate a UI Canvas on a button click that also loads a level.

public void StartLoad(string levelName)
{
    loadScreen.SetActive(true);
    StartCoroutine(LoadLevel(levelName));
}

IEnumerator LoadLevel(string levelToLoad)
{
    AsyncOperation async = SceneManager.LoadSceneAsync(levelToLoad);

    while(!async.isDone)
    {
        yield return null;
    }
}

I am using the UI button OnClick event to call the function StartLoad(string levelName). What happens here is the loadScreen, which is of type GameObject, doesn’t show up immediately when I click the button, but instead flashes briefly just before the levelToLoad is loaded. Any thoughts on how to achieve desired effect? Thanks all for your time!

Maybe it is something about DontDestroyOnLoad()

  • Because when you load a Level you lose the content of the previous already loaded Level
  • So you should create a script that keeps that LoadScreen gameObject while you are loading the new level

Hope it works