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 Gilead7 · Apr 19, 2012 at 08:35 PM · c#playerprefssavingfloats

Invalid floats in PlayerPrefs

I am attempting to save several floats to PlayerPrefs. For some reason, they all come out invalid DWORD Value. The ints and string save perfectly fine. What am I missing?

Here is some code:

public class CharacterGenerator : MonoBehaviour { private float _alignment;

void GenerateStats(){ _alignment=0f; ... } void OnGUI(){ if(GUI.Button (new Rect (392, 300, 100, 50), "Start Game")){

Debug.Log("Start Our Game!"); ... PlayerPrefs.SetFloat("Alignment:", _alignment); ... } Thanks! Please forgive my noobness.

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 rutter · Apr 19, 2012 at 08:42 PM 0
Share

Whatever the problem is, I'm afraid it's not obvious to me. You might try stepping through your code with $$anonymous$$onoDevelop's built-in debugger, with a keen eye on watching the value of _alignment around the time of the error.

Also, remember that you can format your code when editing (select it in the panel, and hit the "101010" button), or use a PasteBin site to post it in a friendly, out-of-the-way format.

avatar image Gilead7 · Apr 19, 2012 at 09:07 PM 0
Share

Thank you!

avatar image Gilead7 · Apr 19, 2012 at 09:37 PM 0
Share

Here is a new wrinkle: I decided to try retreiving one value from player prefs and placed into a debug log statement. It came out without a problem! Anyone have any clues???

3 Replies

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

Answer by yoyo · Mar 08, 2013 at 06:02 PM

The Windows Registry is capable of storing binary data, using the RegSetValueEx function. It appears that Unity is setting a 64-bit binary value into a REG_DWORD key when storing floating point numbers. Regedit can't deal with this, and shows "invalid DWORD", but the data is still there and can be retrieved by Unity (using RegQueryValueEx).

You can see that the data is there in Regedit with right-click > Modify.

So everything's fine, it just looks busted in Regedit. Microsoft problem.

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 Gilead7 · Mar 08, 2013 at 07:43 PM 0
Share

Thanks so much!

avatar image
0

Answer by Kryptos · Apr 21, 2012 at 12:29 PM

Could this be related to the ":" in the name of the saved prefs?

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 Gilead7 · Apr 23, 2012 at 03:55 PM 0
Share

I wouldn't think so, since I used a colon on each and only the floats came back as invalid.

avatar image numberkruncher · Apr 23, 2012 at 04:03 PM 1
Share

That stood out to me as well. I personally like to namespace my preferences using ID style na$$anonymous$$g. player1.character.alignment

avatar image Gilead7 · Apr 24, 2012 at 02:57 PM 0
Share

Why woul dit be fine for ints and strings and not fine for floats?

avatar image
0

Answer by Bunny83 · Apr 23, 2012 at 04:42 PM

You said that you have problems reading the value back. In your code you're just writing it. Are you sure that you use GetFloat? By looking at the error i guess you use GetInt() instead...

copy & paste error?

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 Gilead7 · Apr 24, 2012 at 02:56 PM 0
Share

The problem seems to be in writing the float for some reason. GETting the float is fine, so the value is still there and saved, but in reeditm it shows up as an invalid DWORD. I have informed unity.

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

8 People are following this question.

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

Related Questions

Save Values On Closing of Game 1 Answer

How to save players rotation in Unity? PlayerPrefs 3 Answers

Save/Load Animation State of Instantiated Prefabs 0 Answers

Adding Value to Already Saved Values 1 Answer

I want to save scores and keep incrementing from saved score on restarting the game or in next level/scene? 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