Is there a way to save only certain variables in a class?

Discussion and help for Easy Save 3
Post Reply
baeIsSHOOKETH
Posts: 2
Joined: Wed May 16, 2018 2:23 pm

Is there a way to save only certain variables in a class?

Post by baeIsSHOOKETH »

I'm asking this because whenever I save a certain object that has a class I made in it, ES3 makes a file with huge walls of text just because there's a variable that requires an AudioClip. And since i'm going to need to save MANY of these, saving and loading will probably be super slow. Btw, i'm using the ES3.Save<T>() function. T is the class I was talking about, obviously. Thanks in advance!
User avatar
Joel
Moodkie Staff
Posts: 4848
Joined: Wed Nov 07, 2012 10:32 pm

Re: Is there a way to save only certain variables in a class

Post by Joel »

Hi there,

You can choose which variables are saved using the Types pane: http://docs.moodkie.com/easy-save-3/es3 ... -es3types/

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: Is there a way to save only certain variables in a class

Post by Gladyon »

You can also add the attribute 'Obsolete' to a field or property, that way Unity will still serialize it, but not ES3.
Note that will display a warning when compiling due to the use of an obsolete member.


The warning can be avoided if you search in ES3 source code for the 'Obsolete' attribute, and add another attribute (I use the 'System.Xml.Serialization.XmlIgnoreAttribute' attribute because it's already there and its name is close to the intended behavior, but you can also create your own custom attribute).

You can also do the opposite, having a field or property serialized in ES3 but not in Unity, for that you have to look for the 'SerializeField' attribute in ES3 code, and modify the code in order to add another attribute which will indicate to ES3 that it must serialize the field or property.


Note that the code modifications in ES3 in order to add these 2 attributes are extremely easy to do as very little code has to be added in order to add them.

Speaking about that, would it be possible for ES3 to provide 2 custom attributes, one to force serialization and one to prevent it?
It would allow us to avoid having to create an ES3Type for these features.


[edit]
According to ES3 code It seems that is a field or property begins with 'm_' it will not be serialized.
I haven't tried it but it should work.
User avatar
Joel
Moodkie Staff
Posts: 4848
Joined: Wed Nov 07, 2012 10:32 pm

Re: Is there a way to save only certain variables in a class

Post by Joel »

Hi there,

As this is the first time such an attribute has been requested, I've added a feature request here: https://moodkie.com/forum/posting.php?mode=post&f=14

Note that the method you describe will not work for types for which there is an ES3Type file, as attributes aren't checked in this case.

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: Is there a way to save only certain variables in a class

Post by Gladyon »

Joel wrote:Hi there,

As this is the first time such an attribute has been requested, I've added a feature request here: https://moodkie.com/forum/posting.php?mode=post&f=14

Note that the method you describe will not work for types for which there is an ES3Type file, as attributes aren't checked in this case.

All the best,
Joel
Good to know about the ES3Type files.
The good thing is that it is not a problem as we have other ways to have full control over what is serialized or not for an ES3Type.
baeIsSHOOKETH
Posts: 2
Joined: Wed May 16, 2018 2:23 pm

Re: Is there a way to save only certain variables in a class

Post by baeIsSHOOKETH »

Thanks for the answers. I'll see what I can do!
Post Reply