- Home /
Editing PlayerPrefs directly in plist
In Unity on OSX I am trying to edit the PlayerPrefs values in the unity.companyName.productName.plist, but every time I start the game they get overwritten with the old values. Is there a way to do this directly?
I'm trying to figure out this exact same thing. We're trying to use the PlayerPrefs file as a settings file, where the desired values can be entered/edited directly in the file. I even added a bunch of settings to the file manually. But Unity did not even read them. It only seems to read items that were set by Unity. Even when it's set via Unity, if the plist is updated manually, Unity will somehow still see the Unity set value for that key, and not the manually altered value. And setting any key from Unity, seems to wipe out any manually entered keys that were previously saved there. Weird! If anyone has any ideas, it would be super appreciated! Thanks much!
That's weird. That implies that Unity keeps a separate, secret settings file somewhere else that it can use for backups!
Answer by Eric5h5 · Oct 18, 2011 at 04:49 AM
Quit the Unity editor before editing the .plist file.
What that's it? I thought there was some kind of mystery here...
$$anonymous$$inda sucks to have to exit each time, but thanks!
Sweeeeet! That did the trick. Thanks much Eric!
For anyone using the PropertyListEditor (PLE) on $$anonymous$$ac OS X, here are some things i've figured out that might help, or at least save you some pain:
- You can use booleans in the plist, if you read them using PlayerPrefs.GetInt()
- Using the wrong Unity function for the data type in the plist usually results in 0 being returned. $$anonymous$$g. using GetInt() to read 3.543
- If you enter a number in your plist as 2.0 (because you intend to read it as a float), the PLE removes the decimal value, leaving you with 2!! PlayerPrefs.GetInt() will read that, but PlayerPrefs.GetFloat() will return 0. Sucks if you need that value to be a float. I might end up setting up all my number values as strings in the plist and just parse them via float.Parse() or int.Parse() as needed. $$anonymous$$ind of annoying to have to do that, tho...
- Good idea to save a backup of your plist if you've manually created it, just in case you forget to close Unity while editing the pList and end up wiping out all your manually entered keys!
Thanks again!
I still have the problem with Unity 4.2.2f1 . The file is always overwritten. Quit and restart the application don't work.
Answer by aayars · Feb 01, 2014 at 10:00 PM
Spent some time battling with this, and learned that OS X Mavericks caches prefs in memory. Any manual edits to the plist are ignored. In addition to editing the plist while Unity is closed, you must also invalidate the cache. In my experience, this works:
Quit Unity, make your edit, and then issue these commands in a terminal:
defaults read ~/Library/Preferences/your.plist.here
defaults read your.plist.here
Yes, both commands, and obviously replace your.plist.here with the filename of your plist. Bonus points: make a backup of your plist before trying any of this.
$$anonymous$$an this has been annoying me for ages. I didn't need the second defaults read
command, but otherwise it worked a treat.
can't upvote it, but at least i'll leave a comment here: you've saved my day with this 'defaults' command. thanks.
Using the defaults command is the correct answer since $$anonymous$$avericks, due to all the voodoo caused by cfprefsd.
Your answer
![](https://koobas.hobune.stream/wayback/20220613004535im_/https://answers.unity.com/themes/thub/images/avi.jpg)