I tested using some Debugs and confirmed that it is serializing a List of 16 objects when saving but when I reload the scene and check the Deserialized List (seedDataList) count it is showing 0 but it doesn't return Null. Below is my code, is there something I might be missing as to why I cannot Deserialize the List? I also included the Custom class SeedData for reference and I am using the JSON Data Serializer.
Any help is appreciated, thank you!
Code: Select all
public override string RecordData()
{
var seedDataList = new List<SeedData>();
for (int row = 0; row < gridRows; row++)
{
for (int col = 0; col < gridColumns; col++)
{
var seedData = new SeedData(_plantableAreas[row, col].ItemSeed,
_plantableAreas[row, col].MomentsToDate, _plantableAreas[row, col].GrowthIndex, row, col);
seedDataList.Add(seedData);
}
}
return SaveSystem.Serialize(seedDataList);
}
public override void ApplyData(string data)
{
if (string.IsNullOrEmpty(data))
{
Debug.Log("<color=Red>No Seed Data to load</color>");
return;
}
var seedDataList = SaveSystem.Deserialize<List<SeedData>>(data);
foreach (var seedData in seedDataList)
{
_plantableAreas[seedData.Row, seedData.Col].LoadSeedData(seedData);
Debug.Log($"{_plantableAreas[seedData.Row, seedData.Col].name} Data added.");
}
}
[System.Serializable]
public class SeedData
{
public ItemSeed Seed;
public int MomentsToDate;
public int GrowthIndex;
public int Row;
public int Col;
public SeedData(ItemSeed seed, int momentsToDate, int growthIndex, int row, int col)
{
Seed = seed;
MomentsToDate = momentsToDate;
GrowthIndex = growthIndex;
Row = row;
Col = col;
}
}