Hello folks, May I ask for some help regarding the maintenance of object state between scenes. If I leave scene x with the barn door broken (therefore doorimage = "brokendoor") two buttons on the stove pressed down and one button inactive (topleft = "pressed", bottomleft = "pressed", topright="inactive") and body on floor at a given spot. I move on to scene y, scene z, scene y, scene a and then back to scene x, I want scene x to appear as it did when I left it and not in it's original editor created condition. In other words, store object statuses just before I leave scene x, move away, restore object statuses as I return to scene x and then enter a scene x no different from the one I left earlier. I suspect I am waffling. It's a stress response. To me this seems to be something fundamental in a game, yet I see no obvious way of doing it.Please help. Regards to all
https://unity3d.com/ru/learn/tutorials/projects/adventure-game-tutorial It is a bit old, but still works. The concepts you're asking for still actual for decades.
Well, the cleanest solution is to save ("persist") the Status of your objects when you Exit the Scene, and load it when you enter it, substituting Default values when None are saved. To save info, there are multiple methods, the simplest (for proof of concept), use PlayerPrefs.
gh Thanks. I'll look into it. It seems that PlayerPrefs is really a bad name though, because it implies less than things like my situation and suggests it is only about, well, player prefs and perhaps things like ammo or gold, but not open windows.
Indeed. PlayerPrefs is only to make a proof of concept. A much better way is using a dictionary, and save it as JSON to a temp Directory. Using PlayerPrefs is just a short hack that allows you to verify your idea holds water.
I saved the info to a JSON file, but could not find a method during which I could read the data back before opening the scene. By the time it got to start it was too late, unless the scene was being loaded for the first time/ And you don't want to save and exit before coming back to the scene just to make sure the object data persists.
Ah. Now there's a dirty little trick you can use: save the JSON string to an object that has 'dontDestroyOnLoad' set, so it will persist though scene loads, and read the existing string on start. If it's not present, load default values.