- Home /
Question by
celebritygames · Jan 09, 2017 at 10:52 AM ·
c#persistentdatapath
Persistent data path not loading created file in iOS upon re-opening the game.
My ios game is using the persistentDataPath to save and load the high score of the game. The score is loaded in the start method of the class. Whenever a game ends, the score is saved using the saveTreeCount() method, and the score loads when going to the home screen, but when you fully close out and re-open the app, it fails and the Xcode log says the file can not be found. I know there are a few discussions out there already on this topic, but none of them seem to have the same error as mine.
public void saveTreeCount() {
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + "/playerInfo.dat");
PlayerData data = new PlayerData();
data.highscore = highScore;
bf.Serialize(file, data);
file.Close();
}
public void loadTreeCount() {
if(File.Exists(Application.persistentDataPath + "/playerInfo.dat")) {
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/playerInfo.dat", FileMode.Open);
PlayerData data = (PlayerData)bf.Deserialize(file);
file.Close();
highScore = data.highscore;
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Read XML from Application.persistentDataPath 3 Answers
Saving and Loading Various Things 1 Answer