Is there a way to destroy PlayerPrefs that aren't saved, but keep saved?

I’ve read that Unity saves player prefs to disk when the user quits the application. (I’m doing something for iOS, if that matters).

I would like to record data in PlayerPrefs, but if the user dies before “saving” (where i would call the PlayerPrefs.Save function manually), I want the data to be reverted to the last save position.

If I call PlayerPrefs.DeleteKey will that delete the key from the device itself, or just the most recent entry? That is, if PlayerPrefs.GetInt(“PlayerLevel”) = 5 when the app is turned on, and the player plays, I may make the level 6 or 7 or 8 as they level up, but if they die before they save, can I call PlayerPrefs.DeleteKey and then just re-load from what was saved prior?

You should be fine just calling PlayerPrefs and waiting to call Save() until you actually want to save the data. Calling DeleteKey will remove the key entirely.

But don’t trust me - you can try this out yourself, simply and easily. Just write a script and see what happens.

BTW, if you’re really paranoid, you can just store the data in memory until you’re ready to write it. For instance, you could create a dictionary of type < string , object >. When you’re ready to write to disk, test to see what object is using the is keyword: if obj is float, call PlayerPrefs.SetFloat

You can read more about dictionaries here: C# Dictionary Examples - Dot Net Perls