- Home /
how to persist level/scene state between loading other scenes/levels
I'm fairly new to Unity and Unity scripting. Anyways, I'm working on designing the game state management for the game I'm developing, and I'm wondering how to persist scene data after it is destroyed and then re-loaded via LoadLevel.
Basically, each scene will be a zone/level/landscape, etc., and when the player reaches a boundary, the player will enter a different scene (this is where I assume I'd use LoadLevel). But then what happens when the player returns back to the first scene? From what I've read, the scene will be reset, unless I use a function like DontDestroyOnLoad to the gameobjects/prefabs/etc. in the first scene. But then I'd have to disable all of them and they'd still be in memory (I assume). Is there some way to save the scene state to disk, e.g., programmatically save the scene before loading the next scene?
Now here's another question. I'm considering using a top/root-level gameobject with a bunch of scripts attached to manage various aspects of the game that persist throughout the entire game, such as gamestate. Will loading a scene via LoadLevel destroy this gameobject, so in each scene I will then have to add a script that calls DontDestroyOnLoad for this 'main' gameobject?
thanks, fb
Your answer
![](https://koobas.hobune.stream/wayback/20220613100522im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
"Main" function? 3 Answers
Change level upon clicking a gameobject 2 Answers
Keep GameObject to variable linkage on LoadLevel 0 Answers
Application.LoadLevel() doesn't clear screen 1 Answer
Creating a scene using script (which Start() to use) 2 Answers