Load menu via SceneManager

Updated on April 3, 2019 in [A] 2D
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on April 3, 2019

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:

IEnumerator loadNextScene()
{
 string name = "ALegitSceneName";
 AsyncOperation _async = new AsyncOperation();
 _async = SceneManager.LoadSceneAsync(name, LoadSceneMode.Additive);
 _async.allowSceneActivation = false;
while(!transitionIsDone)
 {
 yield return null;
 }
_async.allowSceneActivation = true;
while (!_async.isDone) 
 {
 yield return null;
 }
Scene nextScene = SceneManager.GetSceneByName(name);
 if (nextScene.IsValid()) 
 {
 SceneManager.SetActiveScene(nextScene);
 SceneManager.UnloadScene(SceneManager.GetActiveScene().name);
 }
}
  • Liked by
Reply