Hello dear community
I’m developing a game for mobile devices, which will have multiple levels to complete. But let’s take Angry Birds as an example, because everybody will know it.
Angry Birds has multiple levels, which can be unlocked and so on. Now my question: Do I create a new scene for each level or should I create GameObjects for each level, which are enabled/disabled? (completing level 1 and pressing a “next”-button will disable level1-object and enable level2-object and so on)
What is better for performance? Having only one scene will definitly save disk space, since I can use the same background object on multiple levels.
What would you suggest?
Thanks in advance, cheers
It depends on the complexity of your level. Complexity in terms of amount of memory which is required for each level. It also includes the number of game objects and their interconnection for different purposes.
- You can combine all the levels into one scene. But do remember that if your game objects take more memory, then create a prefab for each level. And use resources.Load() as LevelX code to load and use Instantiate() to make it appear on scene. Also note that LevelX is sample script that has some data for each level. You can use GameObject class instead for simplicity. Please note whenever you create new level, make sure to destroy the current level and its dependencies. Use resources.UnloadUnusedAssets() method to free memory after destroying it.
- You can combine all or some levels into one scenes based on their memory and dependency requirement. For example assume that your first 10 levels use same platform for running but use different outfits/ obstacles and even different arrangements of obstacles or scene which use common asset. In this case make prefabs of these assets and use in different levels. Activate or deactivate level objects based on conditions or completions.
- Don’t forget that whenever you disable a game object, the object is still in memory but it is not using CPU/GPU for processing. So make sure all your levels or some levels fit the available memory.
- The last one is to split each level into a different scene and load and unload scenes. It is best suitable if each level is almost different or if you face any difficulty in managing all levels in one scene or else fi there is more complexity in interdependency of levels. The best way to this approach is make prefab of all your models and optimise your meshes for models. Try to reuse the assets as best as possible.
Do not keep all game in one scene! Forget this idea
All objects on the scene will upload assets into memory which will make lags(iOS can evaluate your game if it will use too much memory). And game weight depends more on textures and sounds count.
It is better to use prefabs for same gameobjects.
EDIT: once my colegge tryed to keep all game in one scene. Then we spend a lot of time reducing memory usage to stop crashing game on iOS devises. In Android game didn’t crash but it had freezes and lags.
You can make a level editor , build the level , and save the level data to xml file, when game start , just load the level xml file and rebuild the level scene. make all gameobject to prefab and put in “Resources” folder , then you cal using Resouce.Load and instantiate gameobject.