I'm struggling with so simple thing developing game in Unity.
I mark my struct as Serializable. This struct has several fields, including array of custom serializable classes.
[Serializable]
public struct GameSerialized {
public StorageSerialized storage;
public BankSerialized bank;
public object[] buildings;
}
After inspecting JSON output JsonUtility.ToJson(new GameSerialized(game))
unfortunately there is nothing about buildings. Buildings array contains only serializable structs, i.g. HouseSerialized, MillSerialized etc. I think it is the problem of declaration object[]
, because if I declare it e.g. public HouseSerialized[] houses
they are very nicely serialized.
I'd like to use pure language functionality, trying to avoid using custom libs. And I want to do proper architecture, so that game doesn't really know what buildings are inside, as long as they can be serialized.
Thanks for your help.