Hi everyone! I’m trying to reset ALL PlayerPrefs in this one function of my game to 1.) reset controls and 2.) reset unlocked vehicles. Here’s my reset function:
public void ConfirmReset()
{
PlayerPrefs.DeleteAll();
PlayerPrefs.Save();
SceneManager.LoadScene("RedirectionScene");
}
And here’s the logic checking for unlocked vehicles upon loading a scene:
foreach(GameObject vehicle in globalVehicles)
{
Debug.Log("We have fetched " + vehicle.name + " to " + PlayerPrefs.GetString("unlocked_" + vehicle.name, "locked"));
if (PlayerPrefs.GetString("unlocked_" + vehicle.name, "locked") != "locked" && !unlockedVehicles.Contains(vehicle))
unlockedVehicles.Add(vehicle);
else if (PlayerPrefs.GetString("unlocked_" + vehicle.name, "locked") != vehicle.name && unlockedVehicles.Count > 1)
{
Debug.Log(vehicle.name + " should not be unlocked, removing");
unlockedVehicles.Remove(vehicle);
}
}
Now, here’s the thing that’s weird - I use a Debug.Log, and check to see if the player pref changed. It does see that. However, EVEN when I match the player pref to REMOVE a vehicle from the unlocked List, it still doesn’t do it, even when the values match.
Anyone else experienced this kind of problem? How do you deal with it?
To clarify, this only happens during my current run of the game. When I run it again, it works fine, but mainly because of the vehicles not adding to the unlocked collection rather than previously unlocked vehicles getting removed.