Search Unity

Question Issue with unloading start scene.

Discussion in 'Entity Component System' started by mops398, Oct 21, 2022.

  1. mops398

    mops398

    Joined:
    Oct 20, 2017
    Posts:
    14
    Hi!
    I have a boot scene ("boot").
    For entry point of my game I use the following script

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3.  
    4. public class LoadGameScene
    5. {
    6.         [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
    7.         private static void InitializeApplication() {
    8.             SceneManager.LoadScene("game");
    9.         }
    10. }
    11.  
    Usually, in this method I get settings from current scene, but I made it easier for understanding the problem.

    The problem:
    After the DOTS packages was imported in project, I got the strange behaviour of scenes.
    After start of the game in editor, The "game" scene is loaded BUT the "boot" scene is loaded too.
    upload_2022-10-21_11-25-53.png

    Without DOTS in project it worked correctly, and I have the only one scene ("game") in inspector in play mode.

    Maybe the first scene load is async with dots?
    I dont have any ideas, please help
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,892
    Try removing the InitializeOnLoad stuff and instead load the scene in Start, OnEnable or even Update.

    Within InitializeOnLoad some state may not be fully initialized, and in the worst case you prolong the loading of the next scene by 0.0167 seconds - if at all - if you just put it in Update.
     
  3. mops398

    mops398

    Joined:
    Oct 20, 2017
    Posts:
    14
    Yes, If I use Start method then everything work correct, BUT if I use Awake method, I get the same result as in InitializeOnLoad version.

    RuntimeInitializeOnLoadMethod is very usefull for entry point...
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,892
    It really makes no difference for a loader scene. Just put it in Start and move on. ;)
     
  5. mops398

    mops398

    Joined:
    Oct 20, 2017
    Posts:
    14
    I found the solution for my problem. I disabled auto creation on ECS World (set define UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP) and it works correctly not