Why does Unity Editor not reset playerpref values between tests?


This one’s got me scratching my head.

I am saving my users high score with the following code :-

            if (thisScore > PlayerPrefs.GetInt(ScoreVariable))

                PlayerPrefs.SetInt(ScoreVariable, thisScore);

However, as far as I know this value should reset between plays in the Unity editor, However Unity seems to store and recall them every runtime.

Having looked around for support on this, it seems that it is sth. to do with the way the data is written to and then stored in the registry (am on PC).

Any wisdom here would be greatly appreciated.

Thanks y’all.

Playerprefs save variables between games.

When you test your game in the editor you are actually playing a nonbuild-version of your game.

Thus pressing play and stop will act just like if you were actually starting and closing your game → PlayerPrefs will save the variables.

If you want to reset your PlayerPrefs just do: PlayerPrefs.DeleteKey (“nameOfTheVariable”);
Just hook up this code to a button or something. :slight_smile:

Good luck!

Ah…got it, so my understanding was a bit wayward.

Thanks very much for the rapid response, really appreciated.