- Home /
How many prefabs too many?
Instead of making many scenes, or many levels in one scene; which i don't know how to make, I was thinking of making all the levels a prefab. I am making a 2d mobile game btw. So, if there are 200 levels, would it be a problem if I made 200 prefabs? how would it affect the file of the apk? would it suck up too much power from the mobile phone? Please replay if you have an answer, that would be much appreciated.
Thanks in advance
Answer by Setsuki · Aug 28, 2015 at 12:12 PM
A prefab really depends on what it contains, I don't think you can have too many prefabs. However, for several reasons, I would highly recommend you to reconsider :
If your levels are prefabs, then you won't be able to use prefabs IN your levels.
Loading/unloading will probably cause performance issues, since Unity isn't really built like that.
Could you elaborate on why you can't use scenes, or multiple level per scene ? In our current project, we have 4 level per scene (a scene being a world), so I understand there are cases where you'd need a single scene for multiple levels.
i am a novice coder btw. I am trying make a game similar to super meatboy. The camera follows the player, but after the level ends and i try to shift the "camera boundary" and camera to a new position where i have set a new level, the camera shifts back to its last position as oppose to the position i want it to be at, and the camera doesn't follow the player anymore. this is my problem with having multiple levels in one scene. Could you share your way of making multiple levels in one scene, that be really helpful.
Thanks
$$anonymous$$y camera is a child of my character. When the first level is over, the character is teleported to the next level. So the camera is teleported with it. But I still don't understand why you don't want to use multiple scenes.
its just that with multiple scenes, i am going to have to tweak/ assign code individually. Just imagine, if i have 100 scenes. I am going to have to assign code hundred times to an object such as camera. And i read it somewhere that its really not that efficient.
I'd either :
Have a template scene where all that is missing is the level layout (The characters, the finish line, the camera, would be here) and duplicate that scene when I want to create a new level.
DontDestroyOnLoad my character. However, this could be painful to load a game.
Anyway, you CAN use prefabs for your levels, but make sure you manage memory well ; if you don't unload correctly what you don't need anymore, your game performance will be low. However, if you only unload what you don't need, and keep the common objects that are between two level, you'll probably have faster loading times than with scenes.
But realize that you'll need to write more code if you use prefabs than scenes.
Thanks for the advice. I really appreciate it. Btw can you tell me what platform you are releasing you game on? is it mobile? if it is, can you tell me how you optimized your game for multiple screen resolution and aspect ratio?
Answer by Vandie_Studios · Aug 28, 2015 at 12:23 PM
"which i don't know how to make" -OP
To make a new scene, first make sure you've saved your current one before going to file -> new scene. Then when building your game, make sure you add all the scenes in the wanted order in the scenes section of the build window.
Hope this helps, Signed, Vandie