Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Loading screen after start game

Discussion in 'Scripting' started by Kandrbol, Jun 8, 2020.

  1. Kandrbol

    Kandrbol

    Joined:
    Aug 15, 2018
    Posts:
    117
    Hi. I have game in my Android. After click on icons is about 2 seconds logo Unity, and after it 10 seconds black screen. Therefore I make loading screen. But efect no good. Now after Unity logo is 8 seconds black screen and 2 seconds loading screen. Turns out from 40% to 100%. Is there anything I can do about it? After Unity 10 seconds loading screen without black screen?
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,151
    Not sure what you are doing, but if you are using the Unity splash screen feature, you don't actually have to do that if you don't want to. You can have a scene be your "splash screen" and that works just as well in many cases.
     
  3. Kandrbol

    Kandrbol

    Joined:
    Aug 15, 2018
    Posts:
    117
    Between the Unity logo and loading screen is 8 seconds black screen. I only do not want black screen. People may think that the game does not work. Look to
    .
     
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,151
    What are you loading? Looks to me like you might be doing something that maybe is taking some time before the loading bar comes up.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
    Every second spent loading is a few percentage of people who quit, so definitely load SOMETHING, a super-small simple "wheee!! I'm loading!" screen as your first scene, THEN go onto whatever your game does.
     
  6. Kandrbol

    Kandrbol

    Joined:
    Aug 15, 2018
    Posts:
    117
    Exactly. But I do not know how. Therefore I learn and make Scene 0 = LoadingBar. And my game is scene 1. But still is first 8 seconds black screen and after it moment LoadingBar. Is there any settings in the buildgame something? Or is there any other procedure?
     
  7. Kandrbol

    Kandrbol

    Joined:
    Aug 15, 2018
    Posts:
    117
    Like Scene 0 I have LoadingBar.

    Code (CSharp):
    1.  private void Start()
    2.     {
    3.         StartCoroutine(LoadAsynchronously(1));
    4.     }
    5.  
    6.     IEnumerator LoadAsynchronously(int sceneIndex)
    7.     {
    8.         AsyncOperation operation = SceneManager.LoadSceneAsync(sceneIndex);
    9.  
    10.         LoadScreen.SetActive(true);
    11.  
    12.         while (operation.isDone == false)
    13.         {
    14.             float progress = Mathf.Clamp01(operation.progress / 0.9f);
    15.  
    16.             slider.value = progress;
    17.             progressText.text = progress * 100 + "%";
    18.  
    19.             yield return null;
    20.         }
    21.     }
     
    Lucifer95 likes this.
  8. Kandrbol

    Kandrbol

    Joined:
    Aug 15, 2018
    Posts:
    117
    Unity Logo appears immediately. How do they do it?
     
  9. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
    How long does a completely empty project built with that version of Unity and running on that Android OS take to load to the first screen? The difference between that number and your number is the portion you can address.

    Also did you know you can name your scenes by string instead of using numbers? It's much easier to reason about if you are loading a scene called "MainGame" instead of 2, for instance.
     
  10. Kandrbol

    Kandrbol

    Joined:
    Aug 15, 2018
    Posts:
    117
    I will try it.
     
  11. Kandrbol

    Kandrbol

    Joined:
    Aug 15, 2018
    Posts:
    117
    I only build the scene 0 = LoadingBar. After Unity logo is it displayed = 1 seconds.

    It occurred to me that both scenes were loading at the same time.
    Or it is probably loading assets.
     
  12. Kandrbol

    Kandrbol

    Joined:
    Aug 15, 2018
    Posts:
    117
    I think that understand now. I don't have a subscription. The Unity Splash Screen is uniform across all platforms. It displays promptly, displaying while the first Scene loads asynchronously in the background. This is different to your own introductory screens or animations which can take time to appear; this is due to Unity having to load the entire engine and first Scene before displaying them.
     
  13. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    check your awake() and start() scripts in the first scene, dont load assets on the scene 0

    your game only starts to run after the unity splash screen
     
  14. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,151
    Are you using a scene only for your splash, or are you using the splash screen settings? If you use the splash settings, I'm pretty sure that should display right away after the Unity splash....Or with it. I can't recall which.

    If you're using a scene, then just have it be a logo. You can still load the next scene, but you want to make sure your logo is up and displayed while the call to load the next scene is going on.

    Also, there should be an option under Android settings to display a spinning loading icon in the corner, you could just turn that on. I can't recall the exact behavior, but that might be enough.
     
  15. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    Also dont start loading your scene in start() of scene 0, give it 1 second where nothing happens so your loading screen has time to display( you can even fake the animation so it looks like its loading )
     
  16. Kandrbol

    Kandrbol

    Joined:
    Aug 15, 2018
    Posts:
    117
    Yes. Now I understand. I dont speak english and this is my first big project. Therefore I didn't know what it was Splash. Thanks. They didn't say anything about it in the tutorials on you tube. I will be find it and learn, how use it.
     
  17. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Tutorials generally focus on getting the basics working. Things like optimizing loading screens probably don't end up in tutorials.

    Also, when you're experienced enough to create tutorials you probably are using a Plus or Pro license, and the first thing a Plus or Pro license holder does when they create a new project is disable the Unity splash screen :p So you won't see much mentioned about it most likely.
     
  18. Kandrbol

    Kandrbol

    Joined:
    Aug 15, 2018
    Posts:
    117
    Thanks, for your help. I did many attempts all night.
    If start loading scene was in Awake, it does not function.
    If start loading scene was in Start. It does not function.
    But when I gave a 1 second delay with Invoke. It is function. But 1 second is empty screen. Therefore I shortened Invoke. Now I have Invoke("LoadingScene1", 0.01f), and it is still function.
    I tryed again it without Invoke, and It does not function.
    Invoke must be.
    Now I can change graphic design loading bar.
    Look how it function with Invoke 0.01f. 8 seconds black screen is gone.
     
    archana_singh and brigas like this.
  19. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You might just want to start it from the first frame instead of using Invoke. Awake is called while all the objects in the scene are initializing, and Start is called before the first frame. You can call something from the first frame pretty simply using Update
    Code (csharp):
    1. private bool alreadyCalled = false;
    2.  
    3. void Update()
    4. {
    5.     if (alreadyCalled == false)
    6.     {
    7.         MethodToCallOnTheFirstFrame();  //Replace with the name of the method, or whatever work, you want run on the first frame
    8.         alreadyCalled = true;
    9.     }
    10. }
     
  20. haqpod

    haqpod

    Joined:
    Feb 4, 2020
    Posts:
    14
    I had same issue with having 10 sec or so black screen after unity splash screen, and this helped me. To clarify, the solution is simply to wait a short moment before loading your main scene. So just add a little delay in your scene 0 loading scene script that loads the main scene. I did it like this:

    Code (CSharp):
    1. public class LoadingScript : MonoBehaviour
    2. {
    3.     // Start is called before the first frame update
    4.     void Start()
    5.     {
    6.         StartCoroutine(LoadYourAsyncScene());
    7.     }
    8.  
    9.    IEnumerator LoadYourAsyncScene()
    10.     {
    11.         yield return new WaitForSeconds(0.02f);
    12.  
    13.         AsyncOperation asyncLoad = SceneManager.LoadSceneAsync("Main");
    14.  
    15.         // Wait until the asynchronous scene fully loads
    16.         while (!asyncLoad.isDone)
    17.         {
    18.             yield return null;
    19.         }
    20.     }
    21. }
    22.