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 Bregnar · Aug 24, 2012 at 03:22 PM · stringdataread

PlayerPrefs.GetString returns wrong value

Hi, I've got a strange problem.

I save a string in a database and i want to read these data out of this DB.

My string is saved in the DB - i took a look at it and key + value are written in.

Now I'm using the PlayerPrefs.GetData-Method to get my data and it returns always an empty string ( "" ).

This is the code I use to write in the DB:

 PlayerPrefs.SetString("AchievmentsPanty", saveString);

saveString is a string, it's value is like "1,2,3:1,1,0:0,0,0". My DB contains: alt text

To get the data I use this funktion:

 string tmpAchievmentsPanty = PlayerPrefs.GetString("AchievmentsPanty", "");

The second value is the default-value (http://docs.unity3d.com/Documentation/ScriptReference/PlayerPrefs.GetString.html).

tmpAchievmentsPanty contains always "" - an empty string....

Do you know why this happens and how to get the right data out of the DB?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Sundar · Aug 24, 2012 at 03:40 PM

You have misunderstood the function - use this

 string tmpAchievmentsPanty = PlayerPrefs.GetString("AchievmentsPanty");
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 Bunny83 · Aug 24, 2012 at 04:22 PM 0
Share

What's the difference between your way to call the function and his? You just omit the default value which is by default "". So it's actually exactly the same...

http://docs.unity3d.com/Documentation/ScriptReference/PlayerPrefs.GetString.html

avatar image Hoorza · Apr 18, 2018 at 11:16 AM 0
Share

Thank you. Was struggling why is PlayerPrefs returning empty string all the time. I was just using the wrong parameter. Cheers

avatar image Justice0Juic3 · Feb 03, 2020 at 08:23 PM 0
Share

Thank you! Apparently a space in the PlayerPref name bugged the situation over here.

avatar image
0

Answer by Bunny83 · Aug 24, 2012 at 03:37 PM

I'm a bit confused, on the one hand you talk about a DB you're using, on the other hand you talk about "PlayerPref"erences. How is the database related to PlayerPrefs? Are you sure that you store the string with PlayerPrefs.SetString before you call PlayerPrefs.GetString?

Keep in mind that each platform has it's own playerprefs, so setting a playerprefs value in the editor, it won't be set in a standalone build or a webbuild.

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

Answer by Bregnar · Aug 24, 2012 at 04:23 PM

Okay, fixed it.

My script worked well - the only problem was, that I deleted the key at start() because of testing around last night. Thank you all :)

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

11 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

Related Questions

Reading XML Data C# 2 Answers

Cannot read or write a txt file after build 2 Answers

Reading files in Unity from different platform 2 Answers

Reading - Writing data to - from file? 2 Answers

Read string from other script (C#) 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