Search Unity

Multi Scene Load Order

Discussion in 'Scripting' started by RecursiveRuby, Dec 10, 2016.

  1. RecursiveRuby

    RecursiveRuby

    Joined:
    Jun 5, 2013
    Posts:
    163
    Hey so I've been trying to get into the practice of splitting my levels up into scenes. For my game in particular it has loads of useful applications. The environment will remain the same for some levels its just how the game plays that changes. So I kinda have each level split into a few different scenes representing Environment, Managers, Controllers and GUI.

    Managers represent a global form of management in that they don't affect the gameplay they essentially just provide a resource of some sort. Due to this they would need to load before anything else. Controllers represent gameplay control and directly control how the game is played. They depend on the managers to be loaded.

    Basically Managers should load once and could sit throughout the entire life time of the application. Controllers will load on a per level basis. I've just started playing around with using multiple scenes to represent my levels and I can already see the benefits so keep in mind I'm not entirely sure if I'm doing this right.

    I created a Manager Loader which will be used to load the managers. The execution order of that script is set to load first. My question and the issue is despite having execution priority it will still favor calling Awake on scripts in the Active scene before that of my manager scene. I can kind of understand why this is happening and the reasoning behind it. I think. However I'm not sure exactly how I should approach this so that the manager scene receives priority. Production wise I could easily just have it load before any game logic. Editor wise I'm not sure how to do this. Since when I click play all the scenes load at once. I could just set the Manager scene as the active scene although this appears to affect the Lightmapping so I'm guessing that is not the proper way of doing things.

    So if any body has any advice how I should handle something like this I'd really appreciate it. Also what is the Active Scene exactly. In the documentation is describes it as the scene in which new objects are created in. Obviously there appears to be more to it than just that. Also what kind of scene should typically be set as the active scene? Environment, Controllers, GUI etc
     
  2. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    Necro-ing this thread because I have the same question. Did you ever figure this out? Has anyone figured out how to control what order the scenes load when entering play mode while multiple scenes are open?
     
  3. MacStanley

    MacStanley

    Joined:
    Jul 18, 2013
    Posts:
    118
    Anyone has solved this already? I am having a similar issue when having two scenes (one for the player object and some manager objects + scripts and the other for the level. Its's 2D and in my main scene there is a script for pathfinding. This script seems to execute before the second scene is loaded and therefore does not recognize all the level objects that should block the path. If however I set the second scene (with the level) to the active one before starting the game its working fine. Is there a way to prevent scripts from loading before both scenes are loaded without having to write a manager script?
     
  4. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    I never figured out a way, instead I make the second scene the active scene so it loads first, and then the first scene loads second and has a script that sets itself to the active scene.
     
    IgorAherne likes this.
  5. IgorAherne

    IgorAherne

    Joined:
    May 15, 2013
    Posts:
    393