Why Does My Saved Data Not Load?
I was following this tutorial here: https://gamedevelopment.tutsplus.com/tutorials/how-to-save-and-load-your-players-progress-in-unity--cms-20934
Only making a few changes to suit my projects needs, but I must admit I'm pretty new to trying to save data and then retrieve it so I'm doing something wrong but I'm not sure what so any help would be greatly appreciated.
In my save load script I have this, which seems pretty straight forward enough:
public static List<UserSession> savedSession = new List<UserSession>();
public static void Save() {
SaveLoad.savedSession.Add(UserSession.current);
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create (Application.persistentDataPath + "/savedSession.md"); // md = Memory data
bf.Serialize(file, SaveLoad.savedSession);
file.Close();
}
public static void Load() {
if (File.Exists (Application.persistentDataPath + "/savedSession.md")) {
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (Application.persistentDataPath + "/savedSession.md", FileMode.Open);
SaveLoad.savedSession = (List<UserSession>)bf.Deserialize (file);
file.Close ();
}
}
I'm doing this in the part of my script where I want to save some information:
UserSession.lastQorA01.name = "AreYouAspaceship";
SaveLoad.Save ();
print ("I Will Remember This");
Now as near as I can tell it is updating the script: at the top of that same script I have a reference to the "UserSession" script like this:
// Reference To The UserSession Script
public UserSession UserSession;
The User Session Script is pretty much the same as from the tutorial with only minor changes like this:
using UnityEngine;
using System.Collections;
[System.Serializable]
public class UserSession {
public static UserSession current;
public LastThingAsked lastQorA01;
public LastThingAsked lastQorA02;
public LastThingAsked lastQorA03;
public UserSession () {
lastQorA01 = new LastThingAsked();
lastQorA02 = new LastThingAsked();
lastQorA03 = new LastThingAsked();
}
}
Now like I mention as near as I can tell when I change the "lastQorA01" in my script I am trying to save with, it does reflect that in the inspector (See Attached)
But When I try to call the load in my Void Start like this I get nothing??? Can Anyone help me figure this out?
void Start(){
SaveLoad.Load ();
print ("Loaded User Session");
}
Your answer
Follow this Question
Related Questions
A Little Help With Player Prefs 0 Answers
Save Data Android C# 0 Answers
Bug Wtih Unity Cloud Save (Google Play Services) 0 Answers
ScriptableObject created from custom editor lose data on Unity restart 1 Answer
Save/Load Serialization by @Cherno 0 Answers