- Home /
The question is answered, right answer was accepted
Are values in PlayerPrefs cached during a run?
I'm deleting a key from PlayerPrefs while running the game, but when I create the same value, I somehow get back the previous result. However, if I quit the game before creating the same key again, I will get the expected default result. This is why I think there might be a cache, but it doesn´t make sense, and I haven´t seen any information about this in the documentation (although it might have slipped my attention).
To give some more details, I´m storing game options for each player in the PlayerPrefs. I delete a player which also calls PlayerPrefs.DeleteKey() and I know it succeeds, because it disappears from the registry (I'm on windows). Then I create a new player, but with the same name, but if I don't exit the application first, it will get back the same game options values from the PlayerPrefs.
So the question is, are values in PlayerPrefs cached during a run? Thanks in advance for any information!
Answer by robertbu · Jul 15, 2014 at 11:19 PM
Values are cached. Quote from the reference page for PlayerPrefs.Save():
By default Unity writes preferences to disk on Application Quit. In case when the game crashes or otherwise prematuraly exits, you might want to write the PlayerPrefs at sensible 'checkpoints' in your game. This function will write to disk potentially causing a small hiccup, therefore it is not recommended to call during actual gameplay.
Thank you, this was exactly what I was looking for! :)
If I Save() PlayerPrefs after deleting the key it works perfectly!
Follow this Question
Related Questions
password-based checkpoints 0 Answers
What are the prerequisites to learn unity? 2 Answers
Animating y only on an object resembling a bomb 0 Answers
Chat-based text adventure game 0 Answers
Constantly add force and throw an object in every 2 seconds! 2 Answers