Search Unity

Too Many Scenes?

Discussion in 'iOS and tvOS' started by LimeSplice, Jul 18, 2011.

Thread Status:
Not open for further replies.
  1. LimeSplice

    LimeSplice

    Joined:
    Jul 15, 2011
    Posts:
    111
    Hi

    I'm making a game that requires a level up (to 50 levels), and was planning to put each level in a new scene (as there are differences from scene to scene with number of actors etc).

    Can you have too many scenes? I thought this might have been a good way to only load what's required, rather than the entire game into one scene.

    Is this the best approach? Cheers for any advice :)
     
    BrandyStarbrite likes this.
  2. zine92

    zine92

    Joined:
    Nov 13, 2010
    Posts:
    1,347
    Wow for 50 levels, i don't think there's any restrictions and actually if theres some common things, might as well combine a few levels into a scene. Say 5 levels per scene. Depending also. Or you can have something like a scene where it loads a .txt file which reads and assign the level. Say a .txt file which contains certain info like levels and uses that .txt to "recontruct" the level thus you only need 50 .txt rather than 50 .unity scenes.
     
    BrandyStarbrite likes this.
  3. LimeSplice

    LimeSplice

    Joined:
    Jul 15, 2011
    Posts:
    111
    Thanks zine, yeah was thinking of combining levels into batches, however, the way the code is I've spent weeks trying to get it to work correctly (adding to a random array), and haven't been able to (I'm still quite a novice 'coder')... so my only solution was to break all the levels down into scenes... Not sure how to use a .txt file to do this though - didn't think you could! I'll have a look around and see if that could help me... thanks
     
  4. zine92

    zine92

    Joined:
    Nov 13, 2010
    Posts:
    1,347
    I think splitting in batches would be fine for now. And when you have the time, you can try the txt method. The txt method will allow for run time reading of levels which can be change before runtime. :D
     
  5. spentak

    spentak

    Joined:
    Feb 11, 2010
    Posts:
    246
    You can have as many scenes as you want. One of the games I made http://itunes.apple.com/us/app/word-warrior/id400289406?mt=8 Word Warrior, had over 50 scenes..each scene had a lot of content too. The content was built with prefabs too, which means file size was ridiculously low. You could easily do an angry birds with 300+ scenes without any problems. Think of games like Portal 2- You go through well over 100 "loading" sections where it loads a new "scene". This is what Unity is all about.
     
    Kokowolo, Guikg2 and kinguhdahood5 like this.
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    This is the POINT of having scenes in the first place. One per level, regardless of how many you have. There's no overhead and they are tiny. It would be far buggier not to :)

    It's a bit bad to combine multiple levels into one scene, you're only hurting yourself. Just do one scene per level - thousands would work fine. There's no upper limit.
     
    konurhan, Ryiah, Kokowolo and 5 others like this.
  7. Rush-Rage-Games

    Rush-Rage-Games

    Joined:
    Sep 9, 2010
    Posts:
    1,997
    Yep, you can never have too many scenes! ;)
     
  8. MikaMobile

    MikaMobile

    Joined:
    Jan 29, 2009
    Posts:
    845
    It depends on how your game is built, but having lots of scenes might cause problems if/when you add features down the line. Let's say you make 50 levels, and then decide later that you want to add an "options" menu that can be accessed mid game. You'd potentially have to add this menu 50 times to 50 different scenes, unless you build it in a way that's easily plugged into any scene as a prefab or entirely through script. It may not be a huge deal, but it can complicate the process of adding new things. On the plus side, its nice and organized.

    I'd run into issues like this myself when building OMG Pirates, so to make my life easier I used only a single scene for Battleheart, and had all 30-ish levels constructed dynamically via script. The enemies, background art, etc. are all loaded into this one master scene from the Resources folder on Awake(), so if I make any fundamental changes (for instance, changing the camera FOV or something) I don't have to do it 30 times.
     
    BrandyStarbrite likes this.
  9. spentak

    spentak

    Joined:
    Feb 11, 2010
    Posts:
    246
    Mika
    Can you elaborate on your loading of your levels "via script"? What do you mean exactly? If level == 1 then instantiate enemy at x,y,z?Also as for loading resources on Awake(), you load your entire game's resources at the beginning and have those in memory the whole time? Or how does that work?

    On one of my games I ran into the problem with many scenes and feature changes, so I of course made everything into prefabs, and I also had a "filler" prefab for any little thing that might come later. So 1 giant filler prefab with other prefabs in it.

    Is that a bad approach in your opinion?
     
  10. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Mika makes a good point, and to address this you could for example make all "non level stuff" like options in its own script which is not destroyed on load.
     
    Ryiah and BrandyStarbrite like this.
  11. MikaMobile

    MikaMobile

    Joined:
    Jan 29, 2009
    Posts:
    845
    @marklennartprice - all of the battles in Battleheart take place in the same scene. That scene is empty except for a camera, the UI, a big untextured polygon used for the background, and an empty gameobject with a script attached that manages the game. Before arriving in this empty scene, the player had been in a "menu" scene where they chose which battlefield to go to, but these all connect to the same scene. The only difference is what background art, enemies, and party members are instantiated upon entering that scene.

    Basically, anything that differentiates your 50 levels can either be manually placed into 50 discreet scenes... or you can write a system that procedurally recreates those levels in a single scene. I'm not saying one is "better" than the other, but there are some advantages to consider either way. And yes, in some cases you could add something after the fact to 50 scenes by creating it once and setting it to not destroy on load.
     
  12. LimeSplice

    LimeSplice

    Joined:
    Jul 15, 2011
    Posts:
    111
    Thanks everyone for your input. You're right Mika - didn't think of that. I always use prefabs as much as I can, particularly with menu stuff on game screens, so hopefully it won't be an issue. (I still haven't gotten use to the GUI side of Unity yet, so I make 2D button instances lol)
     
  13. LimeSplice

    LimeSplice

    Joined:
    Jul 15, 2011
    Posts:
    111
    @marklennartprice your game looks awesome - is that all 2D sprites?
     
  14. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,076
    Wow!
    I know this is an old post.
    But this is an interesting read. :D
    Thanks for this info guys.
     
    vsxc_VSimpsonXC likes this.
  15. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
  16. skauth

    skauth

    Joined:
    Jun 4, 2017
    Posts:
    17
    So I just accomplished this in my own game. (I know this is post old, but whatevs.)

    Totally not true. Instead of doing this:
    Code (CSharp):
    1. SceneManager.LoadScene(sceneName)
    do this:
    Code (CSharp):
    1. SceneManager.UnloadSceneAsync(oldScene)
    2. SceneManager.LoadScene(sceneName, LoadSceneMode.Additive)
    This will allow you to have multiple scenes open at any one time. Remove the cameras from all the new scenes you create and just stuff the content in there. Use one scene to store all your menu stuff.

    For reference, I'm making a 2D TopDown RPG. Every time you go through a door, I unload the current content scene and load the next content scene (Say 'Town' and 'Hut1'). The Camera, UI, Player, and Managers are all in the 'Main' scene. Any npcs will go in the content scenes. If an NPC is going to follow the player through doors, I'll make it jump to the Main scene. Or I'll make her/him duplicated for each room. I haven't decided yet. Kinda goes along with the debate of making different objects for each quest stage of one npc, or making the one object change.
     
    Digimaster likes this.
  17. ItIsDanDev

    ItIsDanDev

    Joined:
    Jan 8, 2021
    Posts:
    4
    Okay, I'm extremely late to this, but, I'm a bit confused. I'm making a Platformer game and I have made an integer that acts as the Build Index, as it starts at 0 and so on. (Every time you press Next Level in the Menu scene it gets added by one) So I'm using this integer when I'm loading a new scene. Is this the best way? I haven't gotten any errors with it yet, but I don't think this is how I'm supposed to do this. Can anybody give me any advice? (Also, LoadSceneMode.Additive???)
     
  18. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    516
    As long as you test your project thoroughly and you cover all the edge cases, any approach is good.

    https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html
    https://docs.unity3d.com/ScriptReference/SceneManagement.LoadSceneMode.Additive.html

    Loading a scene additively makes you load game objects from a scene alongside your current main scene without unloading it -- when you load a scene with LoadSceneMode.Single, all existing scenes will be unloaded before loading the new one. This allows you to separate your game objects into sections wherever makes sense. Consider an open world game where you have a chunk of the world in a separate scene, loading that chunk additively allows you to only load it when you are near the area, and unload it when you are far away from it.
     
  19. ItIsDanDev

    ItIsDanDev

    Joined:
    Jan 8, 2021
    Posts:
    4
    Oh. Thanks for explaining!
     
  20. glenneroo

    glenneroo

    Joined:
    Oct 27, 2016
    Posts:
    231
    I just discovered here that if increasing your scene count might adversely affect your build times. I was using 3 scenes - build time was 2-3 minutes. I split one of those scenes into ~25 and now my build time is about 10-12 minutes. So my advice would be, if you are considering making a lot of scenes from one scene, considering doing a quick check with few scenes vs many scenes to see how long the build times are.
     
    Last edited: Feb 21, 2022
  21. Charlicopter

    Charlicopter

    Joined:
    May 15, 2017
    Posts:
    125
    My game has over 200 levels in separate scenes and it takes ~45 mins to build from scratch. Using the addressables system reduces the build time to < 1 minute.
     
    Digimaster likes this.
  22. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,076
    I learned from some of the more experienced guys here a few years ago, that the more scenes you use, will increase your build size. Hope that helps.

    Whoever gave that advice years ago, thank you.:D
     
Thread Status:
Not open for further replies.