List of objects won't save
Posted: Wed Aug 05, 2020 6:01 pm
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.
Code: Select all
[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;
}