Search Unity

Solved: Loading screen shows up late and disappears too fast...

Discussion in 'Editor & General Support' started by Firlefanz73, Jan 27, 2020.

  1. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Hello,

    I want to have a loading screen that appears as quick as possible (when starting the game) and shows up until the game is loaded.

    When I search for it, I found multiple samples and all go like this:

    Create a new scene, put your loading Image and or label on it, and load your original Scene then in a script.

    Code (CSharp):
    1. public class LevelManager : MonoBehaviour
    2. {
    3.     // Start is called before the first frame update
    4.     void Start()
    5.     {
    6.         //SceneManager.LoadScene(1);
    7.         StartCoroutine(LoadNewScene());
    8.     }
    9.  
    10.     IEnumerator LoadNewScene()
    11.     {
    12.         // Start an asynchronous operation to load the scene that was passed to the LoadNewScene coroutine.
    13.         AsyncOperation async = SceneManager.LoadSceneAsync(1);
    14.         // While the asynchronous operation to load the new scene is not yet complete, continue waiting until it's done.
    15.         while (!async.isDone)
    16.         {
    17.             yield return null;
    18.         }
    19.     }
    20. }
    But the Problem is this:

    Unity logo is shown very fast. After that there is a very Long loading with a black screen, then there is my Scene with my image but just for half a second...game starts.
    I am aware I could add a waiting time before loading the game scene but this is no useful solution...

    I guess this is because of my many ressources?

    How can I have my loading screen appear much earlier, when the loading is Happening?


    Thanks a lot!
     
  2. diXime

    diXime

    Joined:
    Oct 2, 2018
    Posts:
    162
    Hello,
    My first guess would be that other scripts load before LevelManager.
    In Project Settings, there is a tab "Script Execution Order", maybe you'd want to try and put yours ahead of non-dependent scripts you're not using.
    I'm not sure 100% percent it's what happening here, just that it might get you closer to what you are trying to achieve.



    I've also found this post on the forums regarding the loading screen after the splash that may help too.
    https://forum.unity.com/threads/scene-start-to-load-after-splash-screen.486864/#post-3174132

    Have a nice day !
     
    Firlefanz73 likes this.
  3. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    Do somethin like this:

    Code (CSharp):
    1.         private IEnumerator AsynchronousLoad(int scene) {
    2.             isLoading = true;
    3.  
    4.             _asyncOp = SceneManager.LoadSceneAsync(scene);
    5.             _asyncOp.allowSceneActivation = false;
    6.             while(!_asyncOp.isDone) {
    7.                 if(Mathf.Approximately(_asyncOp.progress, 0.9f)) {
    8.                     _asyncOp.allowSceneActivation = true;
    9.                     FadeScreenFromBlack(1.0f);
    10.                 }
    11.                 yield return null;
    12.             }
    13.  
    14.             yield return new WaitForEndOfFrame();
    15.             isLoading = false;
    16.             yield return null;
    17.         }
     
    Firlefanz73 likes this.
  4. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Yes, this fixed it:

    yield return new WaitForSeconds(0.1f);

    Just added before my LoadSceneAsync...

    Thanks!
     
  5. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    No it doesnt fix it.
    You must use _asyncOp.allowSceneActivation = false; until _asyncOp.progress is almost 0.9f and then you must enable it.
     
  6. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    No it fixed and works perfect. It Shows my Intro Scene and my Image very early.
    The Build is set to my Scene "Intro". It just contains my Image on my canvas with the above script.

    It Shows up early and loads the other Scene. When using your Code, it only Shows the Image again for a very late and short time...

    but thanks for the help!
     
  7. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    It doesnt fix it, you are just lucky on your computer.
    You must check if issplashscreenfinished and you must activate the next loaded scene after you are done with the current.
     
  8. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Thanks for the hint, I'll try that.
     
  9. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Okay, I am now using your Code,
    and in the first line I added

    yield return new WaitForSeconds(0.1f);

    Then my Image appears very early and stays while loading...

    If I do not add this line, I only see it very late after loading for just half a second.

    Thanks for helping!