How to handle levels in Unity3d
I’m making a top-down 2d game in Unity3D for Android-based smartphones. Currently I have two scenes - a preloader and the game itself with all the stuff I need packed into one scene file. Also there is a very simple game-state-manager in my scene. My question now is: Is it better to script all the levels within one scene-file or should I seperate them into unique scene-files? I’m just asking because basically the levels are very similar to each one - only the background and the sprites are different. Is there a problem with memory management if I use one scene only?
Originally, the intention of Unity was that each level of a game should be an own scene. That’s why the method to switch to a different scene used to be Application.LoadLevel (nowadays, you should use SceneManager.LoadScene instead).
You can of course still use that paradigm. The advantage of this method is that you have a very short test-cycle. You can load and edit a level in the Unity scene editor and test-play it just by pressing the play-button.
But many games use a different architecture: Just one general “Play” scene which instantiates the level at runtime.
The information about the level can be loaded from a custom file format. The play scene would have some controller which loads that file and instantiates the necessary objects based on the information in it.
You can also create each level as one prefab and then instantiate the level-prefab from your play scene.
When you wonder which one of these paradigms you should use for your game, consider the following points:
- How important is an instant test-cycle for you? Yes, we all love short test cycles, but are you sure you can keep it that short with reasonable effort?
- How much stuff do you have in every single level which is always identical? If it’s a lot of stuff, then adding it again for every new level can be quite tedious.
- How often do you have something in a level which is completely unique to that level? If you do this often, then it might make sense to use separate scenes for levels.
- Is the Unity scene editor the right tool for building levels for your game or would it be a worthwhile investment to use a separate level editor? If you go this route, you will likely end up with a one-scene architecture.
- Database Administration Tutorials
- Programming Tutorials & IT News
- Linux & DevOps World
- Entertainment & General News
- Games & eSport