what is the best way to save a scene state in game?

I have several scenes connected by javascripts. the scripts will load a the next scene so that the player can explore one scene, go to a different scene, and then come back to the first. I want to be able to save the scene so that it looks the same as it was when the player left it. What is the best way to do this?

Specifically this is important for pickups. I want the player to be able to pickup an object in one scene (the way i did this was to save the name of the object and then instantiate it using the resources folder when I wanted to pull it out again) and take the object to a different scene. when he comes back to the first scene i want the game to load the scene normally but without the pickup object. That is, i want to prevent him from getting the same object twice.

I have no clue how to go about doing this so sorry if this question is vague I just don't know how to start. I can provide additional info about how the game works if you give me an idea of what you would need to know.

1 Answer

1

Make an empty game object which will be your master asset holder. Then in the awake command put DontDestroyOnLoad (transform.gameObject); (this makes the object not be destroyed when you load a new scene). It's best to place this object in a scene that will not be opened again otherwise you'll get a duplicate object.

In the javaScript attached to the asset holder object you can make the scene states that you want to access declared as static variables so your other scripts can easily read them.

So if an object has been picked up give it a variable 1 and if it hasn't give it a variable of 2. Then when the object loads you can get that variable from the master asset holder.

You can also look into PlayerPrefs to keep these variables if a person plays more than once. Then you just load the PlayerPrefs in the start command on the master asset holder.

Thank you very much!

No problem. Good luck with your project.