Page 1 of 1

List of custom objects dont't get serialized

Posted: Thu May 03, 2018 2:07 am
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

Re: List of custom objects dont't get serialized

Posted: Thu May 03, 2018 8:25 am
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