Search Unity

How to preserve an entire game scene?

Discussion in 'Scripting' started by TLoMatt, Jan 25, 2015.

  1. TLoMatt

    TLoMatt

    Joined:
    Jan 25, 2015
    Posts:
    2
    I mean like when you save a game state like emulators and then load at any point . I know there are many solutions based on specific game problems so Im gonna explain mine , I want to pause my game and in the pause menu have a shop button which in the case it's pressed then the game will load a different scene which will be the mentioned shop , my real problem is that I want to save the entire game state meaning all kind of information that is happening , I want to do that just before leaving the game pause scene and resume it when the user leave the shop scene , How can I do that? Thanks
     
  2. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    You would have to decide what data you want to save and serialize that to some kinda data storage like a file.

    If you are doing this simply for loading the store, I would load the store scene as additive than delete it when done with it.
     
  3. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    Yeah, emulators do this by saving the entire contents of the virtual machines memory. That's pretty easy when you're emulating old systems, since they have so much less memory than modern computers. That approach is impractical for a Unity game. There are other ways to implement "save anywhere" in Unity, but suffice to say it's a pretty involved thing, and overkill for your shop case.

    As cmcpasserby says, the best solution for a shop is to use LoadLevelAdditive(). Just make sure that your shop scene has everything under a single, uniquely named load. When you are done with the shop, find that node, Destroy() it and then call Resources.UnloadAllUnused(). Alternatively, you can make your shop a prefab that you instantiate. The idea is basically the same, but the LoadLevelAdditive solution will use less memory when the shop is not active.
     
  4. TLoMatt

    TLoMatt

    Joined:
    Jan 25, 2015
    Posts:
    2
    Well my game will be about space ships and I don't wanna have or add my shop's scene paralell with my paused game :S for 2 reasons: #1 I don't want two have my game scene running paralell with the shop at the same time (because performance , my game will be for mobile cellphones) and #2 cause aesthetically speaking does not look good , my shop will drain performance cause it'll be complex completely diferent and Non basic shop scene is there a way to literally freezze completely a scene in background and load another one new overlaying the main game? And what's a Node ? Sorry but Im new to Unity and that's why I can't understand a lot of things :(