3
\$\begingroup\$

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?

\$\endgroup\$
  • \$\begingroup\$ If the way you're working right now works for you, and you haven't encountered any problems with it, then it's probably fine for the scope & type of game you're making. Are there any specific issues you've observed / heard of that you'd like addressed? \$\endgroup\$ – DMGregory Aug 15 '18 at 15:28
  • \$\begingroup\$ What do you mean with specific issues (sorry if I ask)? \$\endgroup\$ – drpelz Aug 15 '18 at 15:29
4
\$\begingroup\$

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.
\$\endgroup\$
  • \$\begingroup\$ Thanks for your answer. My initial thought was to generate levels with random stuff (like random generated enemies and background-gfx). I'm still wondering it this method could be a problem for memory management (because all stuff is in one scene)... \$\endgroup\$ – drpelz Aug 15 '18 at 15:36
  • \$\begingroup\$ In which case, do you want those same random enemies to persists across levels? (so you run into randomenemy1 on lvl1, and lvl2) If so, you probably want to keep it all on scene. \$\endgroup\$ – Imperial Justinian Aug 15 '18 at 15:41
  • \$\begingroup\$ Well, basically all the stuff I need would persist across all the levels. Therefore my question about memory management on Android-based phones. \$\endgroup\$ – drpelz Aug 15 '18 at 15:47
  • \$\begingroup\$ @drpelz Do I understand it correctly that you have the whole game in one scene and just deactivate everything which isn't in the current level? If so, I could write a paragraph or two about what I think of this architecture. \$\endgroup\$ – Philipp Aug 15 '18 at 15:55
  • \$\begingroup\$ The game objects (prefabs) would be instantiated from level to level based on a random pattern. \$\endgroup\$ – drpelz Aug 15 '18 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.