Does 'ISerializable' work with ES3?

Discussion and help for Easy Save 3
Post Reply
Gladyon
Posts: 30
Joined: Thu Sep 07, 2017 6:51 am

Does 'ISerializable' work with ES3?

Post by Gladyon »

I've tried a basic implementation of 'ISerializable', but it doesn't seem to work when ES3 is saving my class.
And I found no references to 'ISerializable' in ES3 code.

Have I missed something?
If I haven't and ES3 do not call 'GetObjectData()', is there a way to call a given method when ES3 is serializing a standard class (not a custom ES3 type)?
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Does 'ISerializable' work with ES3?

Post by Joel »

Hi there,

Easy Save does not use the ISerializable interface because the majority of Unity's API does not use it at runtime.

Also Easy Save does not have anything similar to GetObjectData() as it writes data directly to the stream, which significantly reduces memory usage and improves performance.

If you need to control what is serialised, you will need to use the Window > Easy Save 3 > Types panel, or create an ES3Type.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Gladyon
Posts: 30
Joined: Thu Sep 07, 2017 6:51 am

Re: Does 'ISerializable' work with ES3?

Post by Gladyon »

Joel wrote:Hi there,

Easy Save does not use the ISerializable interface because the majority of Unity's API does not use it at runtime.

Also Easy Save does not have anything similar to GetObjectData() as it writes data directly to the stream, which significantly reduces memory usage and improves performance.

If you need to control what is serialised, you will need to use the Window > Easy Save 3 > Types panel, or create an ES3Type.

All the best,
Joel
Unfortunately I cannot use an ES3Type, as modders must be able to export/import their own custom data.

All I need is a custom method being called just prior to serialize the data, so I can prepare the data for ES3 to serialize them properly.
I'll take a look into the code to find out where serialization for classes is done in ES3 and add a call to a custom function if an 'IES3Serialize' interface is implemented.
If you can provide any indication about where I should look in the code in order to find where to call such a method, it will help a lot.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Does 'ISerializable' work with ES3?

Post by Joel »

Hi there,

Automatic serialisation (i.e. when no pre-existing ES3Type exists) happens in the Write and Read methods of ES3ReflectedType.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Gladyon
Posts: 30
Joined: Thu Sep 07, 2017 6:51 am

Re: Does 'ISerializable' work with ES3?

Post by Gladyon »

Joel wrote:Hi there,

Automatic serialisation (i.e. when no pre-existing ES3Type exists) happens in the Write and Read methods of ES3ReflectedType.

All the best,
Joel
Thanks for the tip.
I'm not sure why, but I had to put the call in the 'Write()' method of the 'ES3ObjectType' type, but it was close enough.
Anyway now it works fine for my needs, thanks again!


It's very handy to be able to execute some code just before Serialization begins.
It may also be interesting to be called when serialization ends.
Maybe it could a be future feature in ES3, offering the possibility to associate callbacks to some types with a syntax like 'SetOnPriorSerializationCallback(Type, Action)' and 'SetOnPostSerializationCallback(Type, Action)'.
Post Reply