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 /
avatar image
0
Question by djnX · Aug 06, 2019 at 03:13 AM · editor-scriptingplayerprefsresolution settings

PlayerPrefs.DeleteAll() not working in Editor

I tried to build my game and let it run at a fixed resolution.
I changed the setting on Project Setting/Player, but it didn't work. I searched the Internet and found the solution (How to set a Custom Unity Fullscreen Resolution). As I'm using Windows10, Unity saves a registry key in the system. I have to clear the registry key, then the new setting would function well.
Then I found that "PlayerPrefs.DeleteAll()" can help me clear the registry key. I use "PlayerPrefs.DeleteAll()" in game runtime, it works pretty well.
But if I use "PlayerPrefs.DeleteAll()" in Editor (Unity Answers - Why doesn't Standalone Build Resolution settings...), it doesn't work. I checked the registry key, nothing changed.

Comment
Add comment · Show 2
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 xxmariofer · Aug 06, 2019 at 06:53 AM 0
Share

can you create a new script and add this lines in the awake event for example? just for making sure that the issue is with delete all and not with the code re-registring the key after getting deleted

     PlayerPrefs.SetFloat("Unityyyyyy", 5);

     Debug.Log(PlayerPrefs.GetFloat("Unityyyyyy"));

     PlayerPrefs.DeleteAll();

     Debug.Log(PlayerPrefs.GetFloat("Unityyyyyy"));
avatar image djnX xxmariofer · Aug 07, 2019 at 04:08 AM 0
Share

The issue is with delete all.
It seems that new options will not function unless old options have been deleted. So I want to delete all the old options.


I tired your code in my project.
I put them in Awake(). I run the game in Unity Editor (Game View of Unity Editor), getting output 5 and 0.
I put them in editor script (just like the way in Unity Answers - Why doesn't Standalone Build Resolution settings...), getting output 5 and 0.
I also put them in Awake() of a builded game. But I do not know where to see the output.



I re$$anonymous$$ds that, maybe Unity stores registry keys of Unity Editor and builded game in different paths. Using your code I may find the paths.
I change the code, drop most of them, only keep the first line.
I put PlayerPrefs.SetInt("Unityaaaa", 5); in Awake(), run the game in Unity Editor. I put PlayerPrefs.SetInt("Unitybbbb", 5); in editor script, run it. I put PlayerPrefs.SetInt("Unitycccc", 5); in Awake(), then run in a builded game.
Then I search "Unityaaaa" "Unitybbbb" "Unitycccc" in regedit of Windows10. "Unityaaaa" "Unitybbbb" are in H$$anonymous$$EY_CURRENT_USER\Software\Unity\UnityEditor\[company name]\[product name] , "Unitycccc" is in H$$anonymous$$EY_CURRENT_USER\Software\\company name]\[product name].
Very happy seeing things are clear here. Unity stores registry keys of Unity Editor and builded game in different paths. registry keys of Unity Editor are in H$$anonymous$$EY_CURRENT_USER\Software\Unity\UnityEditor\[company name]\[product name]. registry keys of builded game are in H$$anonymous$$EY_CURRENT_USER\Software\[company name]\[product name]. So, if I run PlayerPrefs.DeleteAll() in Unity Editor, registry keys of builded game are not deleted.


Answer in Unity Answers - Why doesn't Standalone Build Resolution settings... works well for many guys, but it is written in 2014. I guess Unity has changed the paths ever since, so the answer not works for me now.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by djnX · Aug 07, 2019 at 04:28 AM

With help from @xxmariofer I may have found the reason.
I'm using Unity 2019.3.0a8 on Win10.
It seems Unity stores registry keys of game running in Unity Editor and game running as standalone in different paths. If I run PlayerPrefs.DeleteAll() in Unity Editor, registry keys of standalone are not deleted.

registry keys of Unity Editor are in HKEY_CURRENT_USER\Software\Unity\UnityEditor\[company name]\[product name]. registry keys of standlone are in HKEY_CURRENT_USER\Software\[company name]\[product name].

Comment
Add comment · Show 3 · 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 xxmariofer · Aug 07, 2019 at 06:22 AM 0
Share

makes sense since the build version should be totally independent to the editor version, do you still need to find a solution to this issue? you will need to create your own playerprefs if you need share key location, i was testing just in case if you added a \ to the key name if you could edit the directory of the keys but no its not posible it would just add the \ to the name. what i suggest is creaating "your own player prefs" and share it accross build and editor you can use the using $$anonymous$$icrosoft.Win32.Registry$$anonymous$$ey for creating keys, checking if keys exist etc...

avatar image djnX xxmariofer · Aug 07, 2019 at 09:33 AM 0
Share

yes, the issue is stilled somehow unsolved.
if I want to delete playerprefs, I have to open regedit and delete manually. Or I can put a button in the game, then delete by click the button in a build version. Either way is kind of wired and inconvenient.
Thank you for your suggestion about $$anonymous$$icrosoft.Win32.Registry$$anonymous$$ey. So I can put a menu item in Editor and then edit keys of build version.

Actually I'm quite new to Unity, many things seem unclear to me. I am considering using my own files as playerprefs, maybe a .json file. Then I may have to control resolution with code. If you have any suggestions about this, very glad to know.
(Another Question. I don't quite understand the pros of using registry on Windows. I think using an option file is much more convenient. But there must be some pros, so many softwares on earth are using registry. What's your opinion?)

avatar image xxmariofer djnX · Aug 07, 2019 at 09:47 AM 0
Share

well, i think that one of the advantages (and i think the main) of usiung windows key registry is that if you want to write to for example Program Files and edit the config you would need to open the app always as an ad$$anonymous$$istrative, also when deleting the game all configuration would get deleted if you use a subdirectory, but whne using the registry you would save it in case they re-install it, i cant think of other advantages but maybe there are. also PlayerPrefs is available across platforms, when you use it with a mobile target for example all player prefs getwritten to a json in a directory. Retrieving data from a json is fairly common and there are easy well-written tutorials that will help you more than me for this porpuse, check this official unity tutorial https://unity3d.com/es/learn/tutorials/topics/scripting/loading-game-data-json

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

125 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 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 avatar image

Related Questions

PlayerPrefs.DeleteAll() changes resolution setting? Looks like a unity bug 3 Answers

How to save the resolution of screen between scenes 2 Answers

Resolution is not saving. 2 Answers

PlayerPrefs - Can I save more than one? 1 Answer

How to set a numerical getint() and display it... 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