Is there a way to save only certain variables in a class?
-
- Posts: 2
- Joined: Wed May 16, 2018 2:23 pm
Is there a way to save only certain variables in a class?
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!
Re: Is there a way to save only certain variables in a class
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
You can choose which variables are saved using the Types pane: http://docs.moodkie.com/easy-save-3/es3 ... -es3types/
All the best,
Joel
Re: Is there a way to save only certain variables in a class
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.
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.
Re: Is there a way to save only certain variables in a class
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
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
Re: Is there a way to save only certain variables in a class
Good to know about the ES3Type files.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
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.
-
- Posts: 2
- Joined: Wed May 16, 2018 2:23 pm
Re: Is there a way to save only certain variables in a class
Thanks for the answers. I'll see what I can do!