Trying to save and load a custom class (SavedChordProgression) on the game starting up. After reading up on the error, I understand why I can’t cast down the inherited hierarchy. However, I am no closer to working out the solution to my problem.
private SavedChordProgression listOfSaves = new SavedChordProgression();
public void save()
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + "/savedGames.mi");
bf.Serialize(file, listOfSaves);
file.Close();
}
public void load()
{
if (File.Exists(Application.persistentDataPath + "/savedGames.mi"))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/savedGames.mi", FileMode.Open);
listOfSaves = (SavedChordProgression)bf.Deserialize(file);
file.Close();
loadAllSaveObjects();
}
}
Thanks very much for your help.