• 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 /
This question was closed Oct 26, 2014 at 11:41 AM by J-F for the following reason:

Figured it out.

avatar image
1
Question by J-F · Oct 26, 2014 at 09:50 AM · playerprefssaveloading

PlayerPrefs.GetInt won't load when awake.

I have a strange problem where my PlayerPrefs.SetInt works and saves just fine, But when i try to load it with void awake or start, the value stays at 0 until something is added to it.

For example: If i have collected 20 items in my game and then reload the game, The item counter is 0 until i pick up another item and then it displays 21, despite the preference being loaded on awake/start.

If you guys have any idea of what's happening please let me know.

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 Bunny83 · Oct 26, 2014 at 09:52 AM 0
Share

Sure, you probably did something wrong ...

Code?

To me that sounds like it's loading just fine, but you did not update the display of your counter.

Please asked more detailed questions. You force us to stab in the dark. This site is for clear and detailed questions that can be answered and not a game called "guess what my problem is".

So please edit your question

avatar image J-F · Oct 26, 2014 at 10:57 AM 0
Share

so this is basically whats going on in my script:

     void Awake() {
         points = PlayerPrefs.GetInt("Score");
 
     }
 
     void OnTriggerEnter(Collider other) {
         if (other.tag == "point") {
             points += 1;
             Destroy(other.gameObject);
             scoreText.text = ""+points;
         }
         if (other.tag == "Exit"){
             PlayerPrefs.SetInt("Score", points);
             PlayerPrefs.Save();
         }

avatar image J-F · Oct 26, 2014 at 11:40 AM 0
Share

Never$$anonymous$$d. i just rebooted unity and it started working just fine, The value in the text was updated by another script which wasn't loading correctly. Thanks for your advice anyways.

0 Replies

  • Sort: 

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

28 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

Related Questions

Loading a save/playerprefs from a different game? 2 Answers

Saving boolean values using PlayerPrefs 1 Answer

Loading error when using PlayerPrefs.GetInt with WebPlayer 2 Answers

PlayerPrefs for saving strings 1 Answer

Saving and loading game with PlayerPrefs 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