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 /
This question was closed Aug 06, 2020 at 12:19 PM by xxmariofer for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by metrislp · Aug 05, 2020 at 11:56 AM · playerprefs

PlayerPreffs not saving between plays?

So I just want to save 3 ints between different sessions, but the values don't get saved and loaded properly. I troubleshot the code and it works properly bc when I used two buttons to manually load and save while running the game it works fine. But between the sessions, it won't save anything. Could it be caused by the inconsistent line endings error? (I don't think so bc in other projects it still worked fine with the error.)

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using TMPro;
   
     public int dayLevel;
     public int Cash;
     public int Diamonds;

     void Start()
     {
 
     Load();
     }
     public void OnApplicationQuit()
     {
         Save();
     }
     public void Load()
     {
         Debug.Log("Load");
         dayLevel = int.Parse(PlayerPrefs.GetString("dayLevel", "1"));
         Diamonds = int.Parse(PlayerPrefs.GetString("Diamonds", "10"));
         Cash = int.Parse(PlayerPrefs.GetString("Cash", "100"));
     }
 
     public void Save()
     {
         Debug.Log("Saved");
         PlayerPrefs.SetString("dayLevel", dayLevel.ToString());
         PlayerPrefs.SetString("Diamonds", Diamonds.ToString());
         PlayerPrefs.SetString("Cash", Cash.ToString());
     }




Comment
Add comment · Show 7
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 · Aug 05, 2020 at 12:31 PM 0
Share

no it is not because inconsistent line ending errors, and 99% sure it is an issue with your code not with playerprefs itself, take into account that if game crashed playerprefs dont get save unless you manually call save yourself. you will need to do a second troubleshot

avatar image game4444 · Aug 05, 2020 at 12:34 PM 0
Share

Please post your code. So that it could be easily to understand your problem.

avatar image metrislp game4444 · Aug 05, 2020 at 06:21 PM 0
Share

Here you go, I added all of the code that is necessary,

avatar image xxmariofer metrislp · Aug 05, 2020 at 06:46 PM 0
Share

well in that code you do nothing they will just have the default value "1" "10" "100" there cant be the error, you need to tell us why you say it is not working, what happens

Show more comments

1 Reply

  • Sort: 
avatar image
0

Answer by metrislp · Aug 06, 2020 at 12:11 PM

So today I opened up my project and the error was gone. It must've been an issue with the engine! Thanks, guys for trying to help me!

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

Follow this Question

Answers Answers and Comments

141 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

Related Questions

Playerprefs resetting after quit 2 Answers

Is PlayerPrefs.Save() necessary ? (My game saves without it) 2 Answers

How to save gameobject values with respect to scene? 1 Answer

Mac: PlayerPrefs not deleted 1 Answer

Unity 4.6: 2 UI sliders updating will not work 2 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