PlayerPrefs.DeleteAll() - Weird Caching Issue

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.

If you clear the playerprefs, then run that second method. The else if would run since the default value is locked and it wouldn’t equal the vehicle name. Are you saying the second debug never shows?

I’m saying that PlayerPrefs.GetString(“unlocked_” + vehicle.name, “locked”) is actually equal to “locked” in Debug.Log, but I can’t actually match it to my string variable containing “locked” - PlayerPrefs.GetString(“unlocked_” + vehicle.name, “locked”) SHOULD equal the string variable containing “locked” but it does not.

For what it’s worth, the second method is from a static singleton type of object. I know there’s been problems with that before.

5385939--546003--upload_2020-1-18_19-25-50.png