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:


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?

the hash they use is djb2-xor

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

string key = name + "_h" + hash;

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)

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.

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");