Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by ProNoob2 · Jul 29, 2019 at 06:36 AM · c#android2derroreditor

PlayerPrefs not debugging

I have some string PlayerPrefs which I am checking in Awake as:

if (!PlayerPrefs.HasKey){PlayerPref.SetString("Price1" + name + parent.name, price1)}

if (!PlayerPrefs.HasKey){PlayerPref.SetString("Price2" + name + parent.name, price2)}

if (!PlayerPrefs.HasKey){PlayerPref.SetString("Price3" + name + parent.name, price3)}

The script is attached to 3 different gameObjects. The script is enabled and the gameObjects are active when the play button is pressed in the editor. But when I debug these in awake() or in start() only one gameObjects values are printed. Others debug nothing. I am confused why?

Comment
Add comment · Show 4
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 xxmariofer · Jul 29, 2019 at 07:10 AM 0
Share

can you copy the full code? since those lines would not even compile and you are not checking anything just setting a new value. But maybe what happens is that the playerpref has a key but the string in that key is empty, but would need extra details

avatar image ProNoob2 xxmariofer · Jul 29, 2019 at 07:39 AM 0
Share

I'm sorry I rechecked the question and in the question I am checking if the PlayerPrefs.Has$$anonymous$$ey returns true whereas in my script I'm checking if it returns false; @xxmariofer

avatar image xxmariofer ProNoob2 · Jul 29, 2019 at 08:46 AM 0
Share

but where are you debugging, did you try what i said? checking if its an empty string? you can use the playerpref destroyall for errasing all keys so all keys get set again

Show more comments

1 Reply

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

Answer by ProNoob2 · Jul 29, 2019 at 10:37 AM

     [SerializeField] private ulong Food1Price;
     [SerializeField] private ulong Food2Price;
     [SerializeField] private ulong Food3Price;
     [SerializeField] private ulong Food4Price;
 
 
  private void Awake()
     {
         PlayerPrefs.DeleteAll();
         stage = transform.parent.gameObject;
         if (!PlayerPrefs.HasKey("Food1Price" + NumFromString(name) + "_" + NumFromString(stage.name)))
         {
             //Debug.Log("Price1" + NumFromString(name) + "_" + NumFromString(stage.name) + ": " + Food1Price);
             PlayerPrefs.SetString("Food1Price" + NumFromString(name) + "_" + NumFromString(stage.name), Food1Price.ToString());
         }
         else
         {
             Food1Price = ulong.Parse(PlayerPrefs.GetString("Food1Price" + NumFromString(name) + "_" + NumFromString(stage.name)));
         }
 
         if (!PlayerPrefs.HasKey("Food2Price" + NumFromString(name) + "_" + NumFromString(stage.name)))
         {
             //Debug.Log("Price2" + NumFromString(name) + "_" + NumFromString(stage.name) + ": " + Food2Price);
             PlayerPrefs.SetString("Food2Price" + NumFromString(name) + "_" + NumFromString(stage.name), Food2Price.ToString());
         }
         else
         {
             Food2Price = ulong.Parse(PlayerPrefs.GetString("Food2Price" + NumFromString(name) + "_" + NumFromString(stage.name)));
         }
 
         if (!PlayerPrefs.HasKey("Food3Price" + NumFromString(name) + "_" + NumFromString(stage.name)))
         {
             //Debug.Log("Price3" + NumFromString(name) + "_" + NumFromString(stage.name) + ": " + Food3Price);
             PlayerPrefs.SetString("Food3Price" + NumFromString(name) + "_" + NumFromString(stage.name), Food3Price.ToString());
         }
         else
         {
             Food3Price = ulong.Parse(PlayerPrefs.GetString("Food3Price" + NumFromString(name) + "_" + NumFromString(stage.name)));
         }
 
         if (!PlayerPrefs.HasKey("Food4Price" + NumFromString(name) + "_" + NumFromString(stage.name)))
         {
             //Debug.Log("Price4" + NumFromString(name) + "_" + NumFromString(stage.name) + ": " + Food4Price);
             PlayerPrefs.SetString("Food4Price" + NumFromString(name) + "_" + NumFromString(stage.name), Food4Price.ToString());
         }
         else
         {
             Food4Price = ulong.Parse(PlayerPrefs.GetString("Food4Price" + NumFromString(name) + "_" + NumFromString(stage.name)));
         }
 }
 
 private void Start()
     {
         Debug.Log("Price1: " + PlayerPrefs.GetString("Food1Price" + NumFromString(name) + "_" + NumFromString(stage.name)));
         Debug.Log("Price2: " + PlayerPrefs.GetString("Food2Price" + NumFromString(name) + "_" + NumFromString(stage.name)));
         Debug.Log("Price3: " + PlayerPrefs.GetString("Food3Price" + NumFromString(name) + "_" + NumFromString(stage.name)));
         Debug.Log("Price4: " + PlayerPrefs.GetString("Food4Price" + NumFromString(name) + "_" + NumFromString(stage.name)));
     } 
 
 private int NumFromString(string testString)
     {
         int testInt = 0;
         string newString = "";
 
         for (int i = 0; i < testString.Length; i++)
         {
             for (int j = 0; j < 10; j++)
             {
                 if (testString[i].ToString() == j.ToString())
                 {
                     newString += testString[i];
                 }
             }
         }
 
         testInt = int.Parse(newString);
         return testInt;
     }


@xxmariofer

Comment
Add comment · Show 2 · 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 xxmariofer · Jul 29, 2019 at 10:59 AM 0
Share

if 3 objects have that same script what will happen is

First you delete all keys and create keys for the first object Second object will delete previous keys and create new key for him Third you delete again previous so you end up with only the keys for your object

easiest solution is to move all your code to the Start event and leave only in the awake the dele$$anonymous$$ll method

avatar image ProNoob2 xxmariofer · Jul 30, 2019 at 05:01 AM 0
Share

@xxmariofer exactly that was happening. Thank you so much for your response.

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

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

Related Questions

"com.google.common.base.verifyexception" Can't build my android game 0 Answers

C# Script - Erro CS8025: Parsing error 1 Answer

Why am I getting this error "Object reference not set to an instance of an object" 1 Answer

Unity compilation error even when VS compiles fine 0 Answers

Unity editor 2019.3.9f1 has error while launching 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