Hi,
I’m trying to save a scene from playerprefs as a new scene, when a button is pressed in a menu level (so not saving the active menu scene).
I’m just wondering if there is a way to take the string from PlayerPrefs.SetInt("SaveGameA")
after it was saved here
PlayerPrefs.SetInt("SaveGameA", SceneManager.GetActiveScene().buildIndex);
after exiting the level to return to a menu, and do something like (in pseudo code):
get the level named “SaveGameA”,
make a copy of it named “SaveGameB”
so that I can later use SceneManager.LoadScene(PlayerPrefs.GetInt("SaveGameA"));
or
SceneManager.LoadScene(PlayerPrefs.GetInt("SaveGameB"));
to create two different games that can be loaded.
I realise that would still only load the same level, but in each of those games there would be the option to go to other levels, so level 1 could go to level 3 and level 2 could go to level 4, for example, the next time an active scene is saved in playerprefs as “SaveGameA” or “SaveGameB”.
Whilst on the topic of using playerprefs to save scenes, is playerprefs used by developers to save data in commercial games?
I’m trying to use EZY Save, but not finding it EZY, and have only thus far been able to save the transform locations of gameObjects when moved around by player.
Thank you for any advice.
PlayerPrefs is best used for exactly what it sounds like. Player Preferences. So, does the user want music level at 50% or did they turn off subtitles. That sort of thing. It does get misused quite often to save more than you really want to use it for in my opinion. Normally if I want to save large amounts of data about char inventory or the level layout, etc, I’m looking at other solutions that can be saved to a file. Or in the case of something where I need to try to keep editing from happening, saving online.
The discussion of saving data can get a bit heavier, but I just suggest a more robust saving and loading system if you need to do a lot of data.
Now, that being said. I have no idea what you are asking with SaveGameA and SaveGameB. You mention saving as a new scene, but what does that even mean? If you’re talking scene in Unity’s term, then I’m not sure what that has to do with PlayerPrefs.
You can certainly Set and Get a PlayerPref and do multiple PlayerPrefs if you want. You can certainly create both a SaveGameA and SaveGameB PlayerPref if you want. But in your example, they are just ints. All you’re doing is loading the same scene. Now if you want to have differences in those scenes, then I would suggest a better save system that is saving those differences.
If you are talking about loading up saved data, then in the case of a save file, you would just access that save file. Your PlayerPref code does nothing except load the base scene that is at whatever index you have at. If you need that scene to have changes, then you have to save out those changes (items collected, enemies killed, whatever you want).