Editor PlayerPrefs getting repopulated with deleted values

I’m having an issue where I can’t properly clear the PlayerPrefs under Mac OSX. I have delete the plist file located under ~/Library/Preferences/, and the old values always comes back. I’ve tried closing the Unity editor completely and then deleting the file, but the values always comes back.

I’ve experienced this behavior with multiple keys from various source. In one case, old PlayerPrefs keys that were no longer in my source code were mysteriously showing up. In another, a plugin that pulled from PlayerPrefs was someone getting old values post PlayerPrefs deletion. This combined behavior makes me think that something in Unity is caching these old values, and since the behavior happened ever after an exit and restart, it makes me think Unity is caching PlayerPrefs to disk somewhere else beside ~/Library/Preferences/.

Any idea what could be keeping the older values around?

I was also baffled to see that every time I changed the .plist file containing the PlayerPrefs, any value read from it would revert to the state of the last execution of my game, overwriting my changes in the file. Removing the file wasn’t cutting it either.

But the culprit wasn’t Unity, it was MacOS: all preferences are actually written through an Apple API and cached (probably in RAM), which makes manual manipulations of the .plist file impossible, unless maybe you reboot your computer or logout/login of your user session.

This got me on the way: http://hints.macworld.com/article.php?story=20130908042828630

If you want to change simple values (non-array, non-nested) , you can use defaults from a terminal. This will change the value and update the cache.

defaults write unity.mycompany.mygame someKey -string 'some value'

For more complicated stuff, this will require a custom script using the CFPreferences API from Apple.

I always have an editor script that adds a menu item that calls a method calling PlayerPrefs.DeleteAll() saves the trouble of having to search for the prefs.