Recursive save of custom types (ES3)

Discussion and help for Easy Save 3
Post Reply
hottabych
Posts: 3
Joined: Tue Jan 16, 2018 7:41 pm

Recursive save of custom types (ES3)

Post by hottabych »

I have a custom type of Slot, that contains some data, and a type of Room, that contains some data and List<Slot>
If I save a Room, seems like it doesn't save inline slots data, only its refs.
save.es3 file contents:

Code: Select all

    "Room_Room (1)": {
        "__type": "Room,Assembly-CSharp",
        "value": {
            "_ES3Ref": 6895361969823577000,
            "_ES3Ref": 6895361969823577000,
            "goID": 8202116442665455754,
            "maxFill": 3,
            "moneyMultiplier": 1,
            "slots": [
                {
                    "_ES3Ref": 3974202846368523016
                },
                {
                    "_ES3Ref": 2797466360452807492
                }
            ]
        }
    },
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Recursive save of custom types (ES3)

Post by Joel »

Hi there,

Items in array fields are stored by reference if they are reference types. If you want them stored by value, you will need to save them separately.

You might also be able to provide an ES3Settings object to tell Easy Save to store by value and reference, but as this functionality is not official yet, we cannot guarantee that this will work:
var settings = new ES3Settings();
settings.memberReferenceMode = ES3.ReferenceMode.ByRefAndValue;
ES3.Save<Data>("saveData", myData, settings);
All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
hottabych
Posts: 3
Joined: Tue Jan 16, 2018 7:41 pm

Re: Recursive save of custom types (ES3)

Post by hottabych »

Thanks, it works like a charm!

Code: Select all

    "Room_Room Bar-1": {
        "__type": "Room,Assembly-CSharp",
        "value": {
            "_ES3Ref": 5831617702258515001,
            "_ES3Ref": 5831617702258515001,
            "goID": 1415775681481571347,
            "maxFill": 3,
            "moneyMultiplier": 1.44,
            "slots": [
                {
                    "_ES3Ref": 6955889909702604742,
                    "_ES3Ref": 6955889909702604742,
                    "goID": 1740974295770544063,
                    "moneyMultiplier": 1.3225,
                    "waitDivider": 1.2
                },
                {
                    "_ES3Ref": 4445572473319895122,
                    "_ES3Ref": 4445572473319895122,
                    "goID": 3284706186407153849,
                    "moneyMultiplier": 1.3225,
                    "waitDivider": 1.2
                }
            ]
        }
    }
Interesting, that loading automatically loads nested types without ES3Settings.
Post Reply