- Home /
The question is answered, right answer was accepted
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());
}
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
Please post your code. So that it could be easily to understand your problem.
Here you go, I added all of the code that is necessary,
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
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!