List of objects won't save

Discussion and help for Easy Save 3
Post Reply
jinxology
Posts: 35
Joined: Sat Sep 13, 2014 5:21 pm

List of objects won't save

Post by jinxology »

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;
}

User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: List of objects won't save

Post by Joel »

Hi there,

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?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
jinxology
Posts: 35
Joined: Sat Sep 13, 2014 5:21 pm

Re: List of objects won't save

Post by jinxology »

Hi Joel,

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.
Post Reply