Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Saving changes in one scene to go back to it later

Discussion in 'Editor & General Support' started by Dezeris85, Dec 16, 2016.

  1. Dezeris85

    Dezeris85

    Joined:
    Dec 16, 2016
    Posts:
    15
    Okay cant seem to find the exact answer to my question. so he we go...

    Say I have a scene and its the planet earth... and you can click on all the countries on the planet. click once a UI pops up telling you everything that country is producing. if you double click on that country..say Brazil. A new scene appears and now you are in like a RTS view/style of game play and you can build buildings. Now if I want to exit out of that scene and do some stuff in the previous scene. Then come back to that Brazil scene later and have it have all changes I made previous still. How is that managed? I know if you load a new scene everything in previous screen gets destroyed and vice versa..I want the main screen to always being played/running though while I'm in the Brazil scene. Should I do this else where in the same scene together by switching from different cameras? If so wouldn't that take up a lot of memory, considering the're hundreds of countries and I would need hundreds of RTS terrain like areas to build for each of them.
     
  2. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,615
    Sounds like you need to save some level data. You would really be loading the same scene in a "default" state, then before actually showing the scene/letting the player interact, you would load up the saved data, and apply any changes to stuff that has changed, so it returns to the same state as before.

    This obviously can get very difficult if you have tons of things that happened, and need to make changes to tons of stuff... but that comes with the territory.

    My advice is get a good system going based on saving out a text file with basic info in it (where an object named X is located in the world, and its changed variables...) for each object that might have changed since the default (anything that can move or be interacted with) and that way you can have a file to try and load up, and then return those variables and stuff back to the gameobjects.

    Sound tedious? It is. I can't think of a better answer off the top of my head, and in your example with an RTS style scene loading up, there are gonna be potentially hundreds of things your gonna need to watch for. Things like where stuff got destroyed maybe, so you can put a carcass in the same place? Things like what animation was playing, and how far through the animation it was, so you can resume the animation? These types of things always vary from game to game, so most of the work your gonna have to custom tailor to what you want to see carried over when the magic is done.

    I know theres a few assets that provide save/load functionality, and I haven't tried any of them, but that is one thing to consider if you wanna buy some decent work in that area rather than write it from scratch. Personally since your gonna need to tweak like crazy anything you buy for this purpose, I'd just write it from scratch and keep it simple. Practice saving a text file (just try saving a string of like "hello world" into a txt file) and then try loading and displaying that saved string in the GUI somehow, so you can get the basic stuff going. Then tackle what type of info needs saved, what kind of format you can use to separate different info (like inserting a comma between values? maybe have the type of value it is there, like "float:1.5, int:2") and how your going to load that data back in (how your gonna find the comma, find the word float and int and recognize where the data is in the string...).

    Good luck!
     
unityunity