Custom savers doesn't reset when restarting game
Posted: Wed Oct 25, 2023 10:53 am
Hi, Tony!
I've got some custom savers. For example this one.
The problem is that if I go to the main menu and start a new game (which will call SaveSystem.RestartGame()) - then all the data will be reset, except for the data of these savers. And if I exit app and then open it and start new game- everything is ok.
I should mention that when I exit to the main menu, all objects are destroyed, so all the savers in the main menu are "clean". Apparently the data itself remains for some reason.
Any idea? Thanks!
I've got some custom savers. For example this one.
Spoiler
Code: Select all
public class InventorySaver : Saver
{
[Serializable]
public class Data //Contains data for serializing
{
public InvItem[] items = new InvItem[6];
public InvItem[] itemsMare = new InvItem[6];
}
//Arrays to operate with
private InvItem[] itemsArray;
private InvItem[] itemsMareArray;
public override void Start()
{
itemsArray = GameManager.Instance.inventory.items;
itemsMareArray = GameManager.Instance.inventory.itemsMare;
}
public override string RecordData()
{
Data data = new Data();
Array.Copy(itemsArray, data.items, itemsArray.Length);
Array.Copy(itemsMareArray, data.itemsMare, itemsMareArray.Length);
return SaveSystem.Serialize(data);
}
public override void ApplyData(string s)
{
Data data = (Data)SaveSystem.Deserialize<Data>(s);
if (data == null) return;
Array.Copy(data.items, itemsArray, itemsArray.Length);
Array.Copy(data.itemsMare, itemsMareArray, itemsMareArray.Length);
}
}
I should mention that when I exit to the main menu, all objects are destroyed, so all the savers in the main menu are "clean". Apparently the data itself remains for some reason.
Any idea? Thanks!