Save and load whole scene
Hello! I don't know why this has to be so complicated, but I am trying to make a game where I can save what scene the player is on when the game saves, and so that when the player comes back to the game they can load the saved scene.
I don't want to load the player's position on that, I just want it to load to the scene the player last saved on.
How do I do this?
Answer by ralphlizard · May 19, 2016 at 05:56 PM
You can get the index of the current scene with SceneManager.GetActiveScene().buildIndex and save that in PlayerPrefs. When you start the game, you can load the scene using SceneManager.LoadScene(int index). Be sure to have "using UnityEngine.SceneManagement;" minus quotes at the top of the script.
Thank you so so so so so so so so so so much! You saved my butt and my game!
i know this was a long time ago, but what? this sounds like diamonds, can you show me how i would put that into
public void Save()
{
//Scene$$anonymous$$anager.GetActiveScene ().buildIndex;
}
public void Load()
{
//Scene$$anonymous$$anager.LoadScene();
}
Totally! For your save function you'd probably want something like this:
public void SaveGame() {
PlayerPrefs.SetInt ("Level", Scene$$anonymous$$anager.GetActiveScene ().buildIndex);
PlayerPrefs.Save ();
print ("Game saved!");
}
And then for your load function you'd want something like this:
public void LoadGame() {
Scene$$anonymous$$anager.LoadScene ( PlayerPrefs.GetInt("Level") );
print ("Game loaded!");
}
Then if you want the game to save you just call the save function and when you want it to load you just call the load function.
can i call the load to i\other scene? like in main menu?
Answer by sr_nada · Oct 12, 2018 at 08:55 PM
Ok, this works well with buttons. But how do I make it work automatically?
sr_nada $$anonymous$$aybe put "SaveLoad.Save();" in your main script under the "Update" function? That is what I did.
Your answer
Follow this Question
Related Questions
How can I save level progression 1 Answer
Having a bit of a problem with loading a save file. 0 Answers
How to save player score? (C#) 0 Answers