I have a data structure like the following
[Serializable]
public class InventoryWrapper
{
public CardInventory[] Data = new CardInventory[0];
}
[Serializable]
public class CardInventory
{
public CardDefinition Definition;
public int Quantity;
}
CardDefinition in the example above is a ScriptableObject class. I’m using the JsonUtility.ToJson and JsonUtility.FromJson functions to save this data structure to disk and loading later.
It appeared to work fine and generates output as follows:
{
"Data":[
{
"Definition":{
"instanceID":377496
},
"Quantity":2
},
{
"Definition":{
"instanceID":377502
},
"Quantity":2
},
{
"Definition":{
"instanceID":-2897598
},
"Quantity":2
}
]
}
This morning all my references broke and when the data is serialised FROM JSON I get null objects instead of references to my ScriptableObjects. Am I going about this in the wrong way? Can anyone help