Page 1 of 1

Recursive save of custom types (ES3)

Posted: Sat Jun 15, 2019 6:14 pm
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
                }
            ]
        }
    },

Re: Recursive save of custom types (ES3)

Posted: Sun Jun 16, 2019 6:08 pm
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

Re: Recursive save of custom types (ES3)

Posted: Sun Jun 16, 2019 6:59 pm
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.