- Home /
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 ;)
I think you mean Application.LoadLevel()
, couldn't find any LoadScene
in unity documentation...
As you can read in the documentation here, LoadLevel()
destroys all loaded objects and loads the new ones from the scene you're loading. It's probably more efficient than destroying the objects one by one, and since you have to load the new objects from scratch anyway, I don't see any reason to write the more complex code... just use LoadLevel()
. If you want to really be sure, do some tests and check which is faster, and by how much.
Yes I meant LoadLevel(). I'll do some tests and see ;)
Answer by rutter · Nov 05, 2013 at 10:23 PM
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().
Thanks a lot for the answer! I'll evaluate what is best for my game
Answer by Point blank interactive · Nov 05, 2013 at 10:10 PM
I'm pretty sure when you LoadScene(), it restarts the scene, and loads the specified one.
Answer by Point blank interactive · Nov 05, 2013 at 10:10 PM
It would be more efficient to instantiate a new one. It would be extremely obnoxious to make hundreds of scenes for randomized levels.
That's true. That's why I made an algorithm that instantiate the squares according to a scheme taken from a String; I was sure it would have come in hand
Your answer
![](https://koobas.hobune.stream/wayback/20220613121317im_/https://answers.unity.com/themes/thub/images/avi.jpg)