List of custom objects dont't get serialized

Discussion and help for Easy Save 3
Post Reply
plourdegui
Posts: 2
Joined: Thu May 03, 2018 1:36 am

List of custom objects dont't get serialized

Post by plourdegui »

I found out that my custom object structure doesn't get serialized as expected.
Whenever I have a list of custom objects, even though the field is annotated with "SerializeField" and the custom object class is annotated with "Serializable", the list doesn't appear in the serialized json stream.

Note that I have not created a ES3Type because my object structure is entirely annotated as it should.
Also note that Unity's serializer does serialize my lists properly: "UnityEngine.JsonUtility.ToJson(PlayerDataModel)"

Here's how I save my object with ES3:
ES3.Save<PlayerDataModel>(PlayerDataModel.GetType().Name, PlayerDataModel);

Attached are:
1. the .es3 file representing the serialized "PlayerDataModel" object: "SaveData.txt" (I had to change the extension from es3 to txt for the file to be accepted by the forum upload system)
2. a file in which I copied both classes (PlayerDataModel and Zone). The reason for putting two classes together is because the forum doesn't allow posting more than 3 attachments: "model.txt"
3. a json file in which I copied the result of Unity's serialization of the same object: "PlayerDataModel.txt"

Now, pay attention at the "zones" field in PlayerDataModel.
It gets serialized properly in "PlayerDataModel.txt" but not in "SaveData.txt"

Could you please tell if this is an issue with the ES3 library or if there is a workaround?

Thank you very much,
Guillaume
Attachments
model.txt
a file in which I copied both classes (PlayerDataModel and Zone). The reason for putting two classes together is because the forum doesn't allow posting more than 3 attachments: "model.txt"
(23.9 KiB) Downloaded 264 times
PlayerDataModel.txt
a json file in which I copied the result of Unity's serialization of the same object: "PlayerDataModel.txt"
(4.75 KiB) Downloaded 250 times
SaveData.txt
the .es3 file representing the serialized "PlayerDataModel" object: "SaveData.txt" (I had to change the extension from es3 to txt for the file to be accepted by the forum upload system)
(2.47 KiB) Downloaded 249 times
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: List of custom objects dont't get serialized

Post by Joel »

Hi there,

I cannot replicate the error at my end with what you've sent as I can't get the scripts to function at my end.

However, it's likely not being serialised because your Zone class does not have a public parameterless constructor. This is not required by the Unity serialiser but is required by our serialiser as Unity provides no method (yet!) for us to create an uninitialised object in a cross-platform way.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply