Search Unity

Load menu via SceneManager

Discussion in '2D' started by drpelz, Apr 3, 2019.

  1. drpelz

    drpelz

    Joined:
    Dec 7, 2017
    Posts:
    69
    I'd like to know if it's a good or bad idea to load the main menu, options and other GUI-stuff via the SceneManager's async-method (additive) into my game (Unity3D).

    The idea behind is that the game might not need so much memory if I load all of the GUI (main menu, options, level selection, achievements, etc.) asynchronously (additive) in my game. Please - can someone help me, please?

    This is some code I found but it doesn't work:
    Code (CSharp):
    1. IEnumerator loadNextScene(){
    2.     string name = "ALegitSceneName";
    3.     AsyncOperation _async = new AsyncOperation();
    4.     _async = SceneManager.LoadSceneAsync(name, LoadSceneMode.Additive);
    5.     _async.allowSceneActivation = false;
    6.  
    7.     while(!transitionIsDone){
    8.         yield return null;
    9.     }
    10.  
    11.     _async.allowSceneActivation = true;
    12.  
    13.     while (!_async.isDone) {
    14.         yield return null;
    15.     }
    16.  
    17.     Scene nextScene = SceneManager.GetSceneByName( name );
    18.     if (nextScene.IsValid ()) {
    19.         SceneManager.SetActiveScene (nextScene);
    20.         SceneManager.UnloadScene (SceneManager.GetActiveScene ().name);
    21.     }
    22. }