I'm trying to save a List<MinimapTile>, but what I end up with is a list of empty objects in the save file. I tested it with a very basic version of the MinimapTile object (called SaveMinimapTile) that DOES work. I have ES3 Types setup for both objects with all the fields checked.
[Serializable]
public class SaveData
{
public List<MinimapData> minimapData = new List<MinimapData>();
}
public class MinimapData
{
public List<MinimapTile> baseTiles = new List<MinimapTile>(); //Doesn't work, it saves the list of (for example) 15 items, but all the objects are empty in the save file
public List<SaveBaseTile> saveBaseTiles = new List<SaveBaseTile>(); //This DOES work
}
[Serializable]
public class MinimapTile : MonoBehaviour
{
public Vector2 loc;
public Minimap minimap;
public TileType tileType;
private void OnMouseDown()
{
// Debug.Log("mouse down floor");
minimap.OnMouseDownCell(loc);
}
private void OnMouseEnter()
{
//Continue erasing if holding button down on enter
if (Input.GetMouseButton(0)) {
minimap.OnMouseDownCell(loc);
}
}
}
[Serializable]
public class SaveBaseTile
{
public bool requiredForMap;
public Vector2 loc;
public TileType tileType;
}
Fields are serialised by reference, which means that if you're saving the List<MiniMapTile> as part of the MinimapData class, the fields of it will not be stored, only the reference ID. If the reference does not exist in the manager, it will not be possible to load it when you reload the scene.
Please could you create a new project which replicates your issue and private message it to me with instructions so I can see what is happening?
I ended up storing things a little differently as a workaround, so no worries on this. If I run into it again, I'll post. Long time user of your great product, thanks for all your hard work.