Keep Scene State!

Hi! im completly new at this, but im making a huge progress.
The thing is, i dont have a clue of how to maintain a scene state, i mean, if the player goes back to the previous scene, it will be exactly as if he never been there (all pick ups, enemys and destroyed objects will be there again).

HOW can i avoid this to happen?

TY and sorry for my bad english.

You are responsible for saving all the positions and reloading them etc.

Nice, but how can i do that? do you have a xample script?

Hi,

You can save the infos in disk or memory, it depends on what you need.

To save on disk you can use PlayerPrefs, (see the docs)

To save memory, you can use DontDestroyOnLoad in a manager object, or you can use singleton (an object with a static reference to an instance of the class)

Or even a combination of these solutions.

My English is bad too :slight_smile:

1 Like

i’ve tried the “DontDestroyOnLoad”, attached that script to the object, but when you come back to the scene, the object is still there (if you pick up a coin, for example, that object gets DESTROY.OBJECT. when you come back to the scene that coin is there,again)

When a scene is loaded, each object that is defined in the hierarchy will be recreated. If you want a different behavior you need to manage the creation dynamically for each situation. Maybe if you describe your problem more specific way, we can help more.

I want SOME of the objects (the ones you destroy) to NOT be created again when you load that scene again
if you destroyed a box on scene 1 and then move to scene 2, when you come back to scene 1, that box SHOULD stay destroyed, and NOT reapear.