- Home /
Levels: scenes or GameObjects?
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 SoBiT
Answer by kumarc123 · Mar 14, 2014 at 07:38 AM
Hello,
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.
Possible Solution
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.
Answer by OSG · Mar 14, 2014 at 07:00 AM
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.
Thanks a lot. I believe you, but I'll wait and look for other answers just to be a 100% sure :)
Disk space depends on the number, size and compression of the textures, 3d models and sound assets (among other stuff), not the number of scenes. A game with one single 14$$anonymous$$B FBX model and one scene will take more disk space than a game with (let's say) 10 scenes with one 1$$anonymous$$B FBX model each. Adding to what @OSG says, getting the whole game into one scene will take forever to load. Not to mention that you will have to manage all the resources if you don't want to have memory issues. Besides, you can still share assets between scenes. And think about what would happen if you wanted to add new levels (Angry birds has a lot of levels). Redo the whole game? Or just create a new scene and link the last scene to it... The latter sounds better to me.
Answer by linkrules · Mar 14, 2014 at 08:45 AM
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.
This answer sound like a good option... but what happening with the "Resourse Folder" these assets are loaded into the memory?