Load Scene. Efficiency question

Hello, I’m making a simple puzzle game (Android) where you have to tap on squares and they rotate; my scene is composed by a plane (to show the background image) and 9 squares in a grid.

I instantiate the squares in Start() with an algorithm. Now my question is: if I want to change to another level, is it more efficient to make a scene for every level and use Application.LoadScene() or wipeing the squares grid and instantiate a new one? (When I LoadScene() does the active scene shut down completely or does it stay frozen somewhere?)

Thanks for your attention :wink:

is it more efficient to make a scene for every level and use Application.LoadScene() or wipeing the squares grid and instantiate a new one?

Depends what sort of efficiency you’re talking about. You can spend a lot of time optimizing your game, but it’s not always the best place to start.

I’d get the core gameplay working, first, and then improve performance from there. This list includes a few steps I might go through for any given feature; the top of the list is usually easier to develop, the bottom of the list usually yields better run-time performance:

  • Reload the entire level, start from scratch each time.
  • Reset the scene: delete key prefabs, instantiate new ones.
  • Reset the scene: reset or recycle prefabs, destroy/instantiate as needed.
  • Reset the scene: use object pools, avoid Instantiate() and Destroy() whenever possible.

Reducing the length and frequency of level loads will keep your player in the game. Reducing the build size will get them into it more quickly. This matters more on some platforms than others (WebPlayer download time matters quite a lot more than standalone PC builds, for example).

It’s not always feasible to create levels dynamically. Maybe you need static lighting. Maybe designers need to be able to tweak certain scenes or events. Unity’s build process can optimize load times quite a bit, if you let it know what assets are actually going to be used.

When I LoadScene() does the active scene shut down completely or does it stay frozen somewhere?

Application.LoadLevel() will generally destroy and unload all GameObjects in the current scene, excepting those that are marked with Object.DontDestroyOnLoad().

I’m pretty sure when you LoadScene(), it restarts the scene, and loads the specified one.

It would be more efficient to instantiate a new one. It would be extremely obnoxious to make hundreds of scenes for randomized levels.