Search Unity

Splash Screen does not execute script code in background?

Discussion in 'Editor & General Support' started by Peter77, Sep 17, 2019.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    I have a question regarding the Unity splash screen.

    I assumed Unity loads and awakes the first scene in "Scenes in Build" list, while the splash screen is displayed.
    https://docs.unity3d.com/Manual/class-PlayerSettingsSplashScreen.html

    However, it seems Unity loads/awakes the scene after the splash screen was displayed.

    I configured the splash screen to last 10 seconds and added the following script to the first scene:
    Code (CSharp):
    1. public class First : MonoBehaviour
    2. {
    3.     void Awake()
    4.     {
    5.         Debug.LogFormat("First.Awake: time={0}", Time.realtimeSinceStartup);
    6.     }
    7.  
    8.     void Start()
    9.     {
    10.         Debug.LogFormat("First.Start: time={0}", Time.realtimeSinceStartup);
    11.     }
    12.  
    13.     void Update()
    14.     {
    15.         if (UnityEngine.Rendering.SplashScreen.isFinished)
    16.         {
    17.             Debug.LogFormat("First.Update: SplashFinished={0}, time={1}", UnityEngine.Rendering.SplashScreen.isFinished, Time.realtimeSinceStartup);
    18.             this.enabled = false;
    19.         }
    20.     }
    21. }
    22.  
    All these Log's come pretty much at the same time.
    Code (CSharp):
    1. 09-17 15:09:11.881 18359 18372 D Unity   : OPENGL LOG: Creating OpenGL ES 3.0 graphics device ; Context level  <OpenGL ES 3.0> ; Context handle -1200478448
    2. 09-17 15:09:11.884 18359 18372 D Unity   : [EGL] Attaching window :0xb8361818
    3. 09-17 15:09:11.893 18359 18372 D Unity   : Requested framebuffer: resolution[1280x800], rgba[8/8/8/8], depth+stencil[on], samples[1]
    4. 09-17 15:09:11.893 18359 18372 D Unity   : Created framebuffer: resolution[1280x800], rgba[8/8/8/8], depth+stencil[24/8], samples[0]
    5. 09-17 15:09:11.894 18359 18372 D Unity   : [EGL] Attaching window :0xb8361818
    6. 09-17 15:09:11.895 18359 18372 D Unity   : Initialize engine version: 2018.4.4f1 (5440768ff61c)
    7. 09-17 15:09:11.932 18359 18372 D Unity   : Begin MonoManager ReloadAssembly
    8. 09-17 15:09:12.818 18359 18372 D Unity   : - Completed reload, in  0.886 seconds
    9. 09-17 15:09:13.148 18359 18372 D Unity   : PlayerInitEngineGraphics OK
    10. 09-17 15:09:13.153 18359 18372 D Unity   : Found 7 native sensors
    11. 09-17 15:09:13.156 18359 18372 D Unity   : Sensor :        Accelerometer ( 1) ; 0.010000 / 0.00s ; kxtj9-accel / Kionix
    12. 09-17 15:09:13.159 18359 18372 D Unity   : Sensor :        Accelerometer ( 1) ; 0.010000 / 0.00s ; kxtj9-accel / Kionix
    13. 09-17 15:09:13.176 18359 18372 D Unity   : SetWindow 0 0xb83fe850
    14. 09-17 15:09:13.176 18359 18372 D Unity   : [EGL] Attaching window :0xb83fe850
    15. 09-17 15:09:13.193 18359 18372 D Unity   : ANativeWindow: (1280/800) RequestedResolution: (0/0) RenderingResolution: (0/0) EGLSurface: (1280/800)
    16. 09-17 15:09:23.340 18359 18372 D Unity   : UnloadTime: 13.021000 ms
    17. 09-17 15:09:23.356 18359 18372 D Unity   : UUID: xxx
    18. 09-17 15:09:23.827 18359 18372 I Unity   : First.Awake: time=10.12555
    19. 09-17 15:09:23.827 18359 18372 I Unity   :
    20. 09-17 15:09:23.866 18359 18372 D Unity   : Sensor :        Accelerometer ( 1) ; 0.010000 / 0.00s ; kxtj9-accel / Kionix
    21. 09-17 15:09:23.875 18359 18372 D Unity   : Choreographer available: Enabling VSYNC timing
    22. 09-17 15:09:23.897 18359 18372 I Unity   : First.Start: time=10.63175
    23. 09-17 15:09:23.897 18359 18372 I Unity   :
    24. 09-17 15:09:24.001 18359 18421 D Unity   : Setting up 1 worker threads for Enlighten.
    25. 09-17 15:09:24.006 18359 18422 D Unity   :   Thread -> id: ffffffff9bc9b930 -> priority: 1
    26. 09-17 15:09:24.377 18359 18372 I Unity   : First.Update: SplashFinished=True, time=11.10229
    27. 09-17 15:09:24.377 18359 18372 I Unity   :
    28. 09-17 15:09:30.532 18359 18359 I Unity   : windowFocusChanged: false
    29. 09-17 15:09:30.590 18359 18359 I Unity   : onPause
    30. 09-17 15:09:30.692 18359 18372 D Unity   : Sensor :        Accelerometer ( 1) ; 0.010000 / 0.00s ; kxtj9-accel / Kionix
    31. 09-17 15:09:30.726 18359 18372 D Unity   : SetWindow 0 0x0

    I assumed Awake() and Start() would be called about the same time the splash screen appears, but they are called after 10secs, when the splash screen finished.

    I want to execute code during the splash screen to async load further scenes to minimize loading times to the first interactible scene.

    Tested with Unity 2018.4.1f1 on Android and Windows Standalone.
     

    Attached Files:

    Last edited: Sep 18, 2019
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    @karl_jones If I remember correctly, you worked on the splash screen feature. Is this is the expected behavior?
     
  3. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,293
    Yes, I wrote the current splash.
    No, we don't execute any code during the splash, this is by design.
    We load the scene in the background while the splash is displayed but we do not activate or run the main player loop until we do the final fade which lasts around 0.3 secs. We don't want to get into a situation where the game is running in the background but the splash is still visible and blocking the view. There is an API to draw the splash manually so you could do something like this:

    1: Disable the splash
    2: Load an empty scene as the first scene.
    3: Call the Splash API in the empty scene and do loading/init https://docs.unity3d.com/ScriptReference/Rendering.SplashScreen.html

    The advantage of this is you can then let users press any key to quit the splash when you are ready
     
    Last edited: Sep 15, 2020
    Peter77 likes this.
  4. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    Thanks for the quick reply and help Karl!

    My current workaround works actually pretty good, I just wanted to clarify whether the current implemented splash behavior is by design.

    Using a custom splash screen was a great way to significantly reduce the time to reach the first interactive screen in our game, since we can use the splash time to load and initialize stuff in the background.
     
    Last edited: Sep 15, 2020
    karl_jones likes this.