Hello everyone,
I’m currently doing, for the first time, a save/load system and right now I’m only doing it for the game’s settings. I’m currently getting all the data from 3 different scriptable objects into a custom class (not monobehaviour) called “Settings”. Then I made that class a [System.Serializable] and used it on another class called “SaveManager”, that is part of my GameManager (GameObject that is not destroyed on load and has a public static instance).
My save and load methods look like this:
private void SaveObject(object objectToSave, string path)
{
Debug.Log($"Saving to {path}...");
BinaryFormatter binaryFormatter = new BinaryFormatter();
FileStream file = new FileStream(Application.persistentDataPath + path, FileMode.Create);
binaryFormatter.Serialize(file, objectToSave);
file.Close();
}
private void LoadObject(object objectToLoad, string path)
{
Debug.Log($"Checking from {path} file...");
if (File.Exists(Application.persistentDataPath + path))
{
Debug.Log($"Loading from {path}...");
BinaryFormatter binaryFormatter = new BinaryFormatter();
FileStream file = new FileStream(Application.persistentDataPath + path, FileMode.Open);
objectToLoad = binaryFormatter.Deserialize(file) as Settings;
file.Close();
}
}
And are then called like this:
public void SaveSettings()
{
Settings settings = new Settings(graphics, audio, keybindings);
CheckSaveLocation(Action.save, "/Saved");
CheckSaveLocation(Action.save, "/Saved/Settings");
SaveObject(settings, "/Saved/Settings/settings");
}
public void LoadSettings()
{
Settings settings = new Settings(graphics, audio, keybindings);
CheckSaveLocation(Action.load, "/Saved");
CheckSaveLocation(Action.load, "/Saved/Settings");
LoadObject(settings, "/Saved/Settings/settings");
}
Now onto the problem:
It saves and loads without a problem but when I look into the saved file it does not look like it is saved as a binary file…
What I expect it to look like:
What it looks like:
I feel like I’m doing something really wrong… Please enlighten me!
Thank you!
EDIT:
I tried to build the game and it does not save on build. So it works on editor but not on build… Weird! Any ideas?