• 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
4
Question by Ony · Oct 19, 2011 at 12:24 AM · playerprefsupgrade

PlayerPrefs changing the name of keys?

I am in the process of updating my game from 2.6 Pro to 3.x Pro. I've noticed something very strange about the way PlayerPrefs is working.

When I save a value via PlayerPrefs, it keeps adding a suffix after the key name in the registry (using Windows 7 - 64).

For instance, the following code:

 PlayerPrefs.SetString("justTesting", "TEST!");

It saves into the registry, BUT it changes the string name to the following:

 justTesting_h3837386411

It adds a "_hxxxxxxxxxx" suffix to every key I save. Each time it has the "_h" but the number sequence is different. I can't for the life of me figure out why it's doing this. Anyone have any ideas?

Comment
Add comment
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

4 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by jahroy · Oct 19, 2011 at 01:01 AM

That's probably data that's internal to Unity that you're not supposed to understand. It might have to do with how/where it's storing data or anything under the sun.

This only appears in the registry editor right? (I assume these values don't appear when you access the data from your game)

Comment
Add comment · Show 1 · 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 Bunny83 · Oct 19, 2011 at 02:29 AM 0
Share

It's actually some kind of hash value of the key-name itself but nothing i can identify :D. It generates always the same hash for the same text.

avatar image
7

Answer by Lance Sun · Jan 20, 2012 at 01:56 PM

the hash they use is djb2-xor

 uint hash = 5381;
 foreach (char c in name)
     hash = hash * 33 ^ c;

 string key = name + "_h" + hash;
Comment
Add comment · Show 1 · 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 TimmermanV · Jun 25, 2020 at 02:27 PM 0
Share

This works great, thanks.

avatar image
0

Answer by Ony · Oct 19, 2011 at 01:10 AM

The problem is that my installer sets up a whole range of variables in the registry, and those variables are all being ignored now when Unity reads them. It ends up making its own keys with that suffix on the end, and doubling up everything in the registry (one key will be "Path" for instance, and another is "Path_h3827827302").

Is this something that Unity 3 does to everyone or is it just happening on my system? I'd prefer it just names things what I name them, instead of adding on some arbitrary suffix to the keys.

Comment
Add comment · Show 4 · 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 jahroy · Oct 19, 2011 at 01:21 AM 0
Share

Is Unity giving them a random name because you're installer is creating them first (and Unity doesn't want to overwrite them)?

Or does Unity name them like that for its own purposes?

I don't know the answer to these questions.

avatar image Ony · Oct 19, 2011 at 04:45 AM 0
Share

Unity writes them that way regardless of whether the key exists or not.

avatar image Orion 1 · Oct 19, 2011 at 08:07 AM 0
Share

I'm experiencing the same problem. It really clutters up the registry. I wouldn't be surprised if it's something they needed for Android or iPhone phones but forgot to disable in Windows - since before that registry entries worked just fine on any Windows version.

avatar image Eric5h5 · Apr 04, 2012 at 02:15 AM 1
Share

@Orion 1: no, it's a way to avoid name collisions, specifically because of the registry in Windows, and not needed or used for anything else.

avatar image
0

Answer by DaveA · Apr 03, 2012 at 11:49 PM

Seems you can, on Windows anyway, use the Registry class to 'roll your own' player prefs to get around this. Eg:

 var rkey :RegistryKey = Registry.CurrentUser.OpenSubKey("Software\\MyCompany\\MyApp");
 rkey.SetValue("justTesting","TEST!");
 rkey.Close();
Comment
Add comment · Show 1 · 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 Lance Sun · Apr 04, 2012 at 01:50 AM 0
Share

if the concern is only with registry keys generated by using PlayerPrefs, which is the question asked, then your solution works i think (i'm not sure what cross-platform considerations there are).

this wasn't the question posed, but for our project, we needed to work with the "standard" registry values that unity uses, such as the video settings, and had to contend with the appended hash. we could scan the registry key for value names that begin a certain way, such as "UnityGraphicsQuality_", and that would work. but in some situations, we needed deter$$anonymous$$istic knowledge of the registry value name. specifically, we have a custom "launcher" that includes an options dialog for graphics settings. we could have used unity's builtin one, but there was no way to hide the input tab. also, our launcher also serves as the patcher, includes an rss news feed, and has other requirements. with a custom launcher, on first run, there will be no registry values set, but our launcher still needs to be able to set video options. we needed to be able to predict the registry value names to support this.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

8 People are following this question.

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

Related Questions

PlayerPrefs - Registry Values stored as invalid DWORD 2 Answers

Where do I put PlayerPrefs.SetInt? 1 Answer

Unity adds strange number to registry entries 2 Answers

Deleting PlayerPrefs Data 1 Answer

Load NSUserDefaults from previous Android app. 0 Answers


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