Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by junctioniv · Aug 21, 2014 at 04:21 AM · c#playerprefs

PlayerPrefs - Registry Values stored as invalid DWORD

Hi Unity Answers,

Out of some weird circumstances, I need to programatically read all the values of playerprefs stored in the registry, and not simply use PlayerPrefs.GetFloat(). When using Regedit I saw that the float registry keys value was REG_DWORD and not a REG_QWORD or REG_BINARY. Also the value is listed as "(invalid DWORD (32-bit) value)". When you view the hex-data stored it seems to have a value, but it does not correlate to the actual value stored in unity.

When I read the value stored at the keys, I get completely different values. For instance I have a float stored in unity with a value of 1, the hex value shown in Regedit is 00 00 00 00 00 00 F0 3F and the value converted to a float is 4.60718242E+18. The strange thing is that unity still can read and process these values correctly. The function I am using to process the reg values is bellow:

 public void ReadRegistryKeyValues()
 {
    RegistryKey rk = Registry.LocalMachine.OpenSubKey("Software\\" + PlayerSettings.companyName +"\\" + PlayerSettings.productName , false);
     foreach (string key in rk.GetValueNames())
     {
         var currentKey = rk.GetValue(key);
         if(currentKey != null)
         {
             if(currentKey.GetType().Name == "Int32")
             {
                 int r = Convert.ToInt32(currentKey);
             }
             if (currentKey.GetType().Name == "Int64")
             {
                 float r = Convert.ToInt64(currentKey);
             }
             if (currentKey.GetType().Name == "String")
             {
                 string r = currentKey.ToString();
             }
         }
                 
     }
 }

Does anyone know how to read the invalid DWORD correctly in c#? Or does anyone know of a Way to force C# to read this key as QWORD? Does a Unity Software Engineer want to reveal the process they use to read these invalid reg keys?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by pacific00 · Aug 21, 2014 at 06:20 AM

if i understood correctly , you can use PlayerPrefs.GetFloat for reading the values..

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 junctioniv · Aug 21, 2014 at 09:57 PM 0
Share

As stated, I need to read the registry keys directly and cannot use Playerprefs.getFloat().

avatar image
0

Answer by Saltsalesman · Feb 12, 2019 at 11:50 PM

I had to deal with this today, and TL;DR:

Float values in playerprefs are stored as 64-bit doubles. You need to pull them down like this:

 string keyName = @"Software\\MATTCO\\TESTFLOATS";
 RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName);
 Object o = key.GetValue(value);
 long lData = (long)o;
 var bytes = BitConverter.GetBytes(lData);
 double dubs = BitConverter.ToDouble(bytes, 0);
 Console.WriteLine($"Double Value: {dubs}");
Comment
Add comment · 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

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

6 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

PlayerPrefs - Can I save more than one? 1 Answer

How To Add PlayerPrefs Scores? 1 Answer

Highscore GUI not working properly help 0 Answers

Distribute terrain in zones 3 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