Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
5
Question by youblistermypaint · May 13, 2016 at 01:13 AM · playerprefsmacosx

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?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Morgan · Oct 05, 2016 at 11:24 PM 0
Share

Same here (5.4): I exit Unity and delete the plist from ~Library/Preferences, and yet values somehow come back! $$anonymous$$akes my title fail, and I cannot start fresh.

avatar image kayy · Oct 07, 2016 at 03:55 PM 1
Share

Seems to be platform independent as I noticed the same behaviour under Windows (7). Deleted registry keys are showing up out of the dark

avatar image youblistermypaint · Oct 07, 2016 at 05:15 PM 0
Share

I don't have time right now, but it would be great if someone could open a bug with Unity about this. The behavior is fairly easy to demonstrate with the BundleVersionChecker Plugin. Just create a new project, add the plugin, select a directory for the plugin output and delete the plist and the value should still exist.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by AlexisDow · Aug 10, 2017 at 06:56 PM

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Morgan · Aug 10, 2017 at 07:22 PM 0
Share

Very useful! That may explain why I've had SO$$anonymous$$E luck quitting the editor before making changes. $$anonymous$$ight cause the cached data to be dealt with?

avatar image AlexisDow Morgan · Aug 16, 2017 at 08:56 AM 1
Share

I think in this case it was just luck :) $$anonymous$$e trying to open/close the Editor didn't change a thing. Again, this has nothing to do with Unity, so you probably made a change just before a scheduled refresh of the cache by the OS. Again, I am just speculating here.

avatar image
1

Answer by Naphier · May 13, 2016 at 06:35 AM

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.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image youblistermypaint · May 14, 2016 at 05:06 PM 0
Share

I did use a work around to resolve my particular issue. I'd still really like to know where these mysterious values are co$$anonymous$$g from.

avatar image Naphier youblistermypaint · May 14, 2016 at 07:09 PM 0
Share

Depends on what they are. Every time you run a build, Unity is saving some stuff to player prefs. On windows it is the window height/width and quality settings. Plus a couple other things I'm not sure of. So when in development I often have to reset player prefs when I change the dimensions of the exe's window.

avatar image youblistermypaint · May 14, 2016 at 10:50 PM 0
Share

I updated the question with more details about the behavior I am seeing. Should hopefully make it clearer.

avatar image Morgan · Oct 07, 2016 at 04:00 PM 1
Share

PlayerPrefs.DeleteAll() does successfully clear the data, wherever it's being cached.

(In my case, I didn't bother with an editor script, just stuck that in my project, ran it, then commented it out once the bad prefs were gone.)

avatar image krisventure · Apr 15, 2017 at 03:31 PM 0
Share

This sounds like a Unity bug. Unity should NOT transfer the PlayerPref values added by my game in the Editor into the build.

First of all, if we need to remember to manually clear the PlayerPrefs before each build for releasing a new update for our games etc, we're running the risk of forgetting it and having our new users inheriting whatever settings we had in our Unity project for testing. It's our responsibility to do our best to test everything before an update is released of course, but it's Unity's responsibility to provide optimal default behaviour to help with that. That would be to remove those PlayerPref values from the build by default.

On the other hand, I should be able to keep those PlayerPref values in my Unity project, not having to delete them just to exclude from the build if I don't want to.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

62 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

PlayerPrefs Not Saving When I Click the Button. 1 Answer

PlayerPrefs works fine in Unity Editor but not on Android 0 Answers

Best practice for storing template data plus character data? 1 Answer

Unity2D: PlayerPrefs.HasKey 0 Answers

Please help how to save last index and load 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges