Page 1 of 1

ES3UserType parameterized contraints and ES3Serializable

Posted: Thu May 13, 2021 5:28 am
by robotSmith
Hello, hello.

I have two questions:

- I'm trying to make sense of the constraint on parameterized constructors. If I'm adding a constructor is because I want it to be initialized by a specific implementation, and very likely there would not be default values. In addition to this, I will have an Assert at the constructor to make sure that there are no Null values or empty Lists arriving to the constructor as that would be an error. Any comments on how to get around this without skipping on defensive coding patterns?

- Would you mind expanding a bit more about "ES3Serializable", what's the difference with "Serializable" or "SerializeField"? When should I be using?

Thanks in advance!

Re: ES3UserType parameterized contraints and ES3Serializable

Posted: Thu May 13, 2021 7:20 am
by Joel
Hi there,

I'm afraid I'm unsure what you mean by "ES3UserType parameterized contraints". Do you mean the requirement for classes you're serializing to have a parameterless constructor?

You can use ES3UserTypes to serialize a class with a parametric constructor, and a good example of this is the built-in ES3Type for Vector3 which you can find in Plugins/Easy Save 3/Scripts/Types/Unity Types/ES3Type_Vector3.cs.
Would you mind expanding a bit more about "ES3Serializable", what's the difference with "Serializable" or "SerializeField"? When should I be using?
The only difference is that Serializable and SerializeField will be used by both the Unity Editor and Easy Save, whereas ES3Serializable will only be used by Easy Save.

All the best,
Joel

Re: ES3UserType parameterized contraints and ES3Serializable

Posted: Fri May 14, 2021 3:15 pm
by robotSmith
Correct, I was talking about needing parameterizedless constructors. Based on this, a couple of questions:

- Do you see any problems with having multiple constructors? It seems that I can just choose the one with the least amount of info required when modifying the ES3UserType on the ReadObject

- What is the best workflow to deal when changes happen to the custom type that ES3UserType is using? For example, I added a new field, or I'm changing the private fields into public properties, or I'm removing a field? Not necessarily talking about data already saved, but about how to "reset" the ES3UserType.

- And based on these conversation, it seems that if I have a parametless constructor, ES3 will support it automatically and do the changes itself without me managing the members and instantiation. Would this be correct?

BTW. Your user guide might be a big behind with some name changes for custom types:
ES3Type vs ES3UserType
WriteComponent vs WriteObject
RedComponent vs ReadObject

As always, thanks a lot for your help!

Re: ES3UserType parameterized contraints and ES3Serializable

Posted: Fri May 14, 2021 3:21 pm
by Joel
Hi there,

It's quite normal for classes to have multiple constructors, so I can't imagine there would be any problems.

Whenever you changed a type you would need to change its appropriate ES3Type to reflect this. However, as long as you're using the try/catch statement included by default in the ES3Type, previous save data will still be valid.
And based on these conversation, it seems that if I have a parametless constructor, ES3 will support it automatically and do the changes itself without me managing the members and instantiation. Would this be correct?
I'm afraid I don't understand the question.
BTW. Your user guide might be a big behind with some name changes for custom types:
ES3Type vs ES3UserType
WriteComponent vs WriteObject
RedComponent vs ReadObject
This isn't an error in our guides.

An ES3UserType is an ES3Type created by a user through the Types pane. WriteComponent is used when generating an ES3Type for a Component, whereas WriteObject is used when writing object types. This happens in the background when you use the Types pane, so these will automatically be generated for you and don't need to be documented.

All the best,
Joel

Re: ES3UserType parameterized contraints and ES3Serializable

Posted: Fri May 14, 2021 4:23 pm
by robotSmith
Joel wrote: Fri May 14, 2021 3:21 pm
Whenever you changed a type you would need to change its appropriate ES3Type to reflect this. However, as long as you're using the try/catch statement included by default in the ES3Type, previous save data will still be valid.
What do I need to do to change the ES3Type? I was talking about the one that you create through the Type panel in the Inspector, and I think you are talking about it too. Does this mean go into the the c# script of the type? Or should I got into the Type panel, re check the parameters?, Or should I go into the panel and restore default and recreate the ES3Type? What would be your recommended approach.
Joel wrote: Fri May 14, 2021 3:21 pm
And based on these conversation, it seems that if I have a parametless constructor, ES3 will support it automatically and do the changes itself without me managing the members and instantiation. Would this be correct?
I'm afraid I don't understand the question.
If I create an object that I want to save and it does not have a parameterless constructor, it seems that I have to do this:
- Create the ES3Type that will give me a ES3UserType
- Modify the script to add the default constructor
- Whenever I add or remove fields, I would need to change the ES3UserType in the Type panel (well, depends on the first conversation above)
- Modify the script to possibly modify the default constructor

It seems that ES3 handles all this by itself if I have a parameterless constructor. Is this correct?

Joel wrote: Fri May 14, 2021 3:21 pm
BTW. Your user guide might be a big behind with some name changes for custom types:
ES3Type vs ES3UserType
WriteComponent vs WriteObject
RedComponent vs ReadObject
This isn't an error in our guides.

An ES3UserType is an ES3Type created by a user through the Types pane. WriteComponent is used when generating an ES3Type for a Component, whereas WriteObject is used when writing object types. This happens in the background when you use the Types pane, so these will automatically be generated for you and don't need to be documented.
Well, I was trying to add an object without a parameterless constructor and I had to add it through the Types panel. The types panel created the script which is prefixed "ES3UserType_". After that, the script has an error because is trying to instantiate the object without parameters, which makes sense, and I have to add the default instantiation. Everything that I just mentioned happens inside ES3UserType, not ES3Type. And the methods I mentioned are within ES3UserType that it's asking me to change. Or am I doing something very wrong here?

Here is a pic
PictureES3.PNG
PictureES3.PNG (87.52 KiB) Viewed 1126 times

Re: ES3UserType parameterized contraints and ES3Serializable

Posted: Fri May 14, 2021 4:29 pm
by Joel
What do I need to do to change the ES3Type? I was talking about the one that you create through the Type panel in the Inspector, and I think you are talking about it too. Does this mean go into the the c# script of the type? Or should I got into the Type panel, re check the parameters?, Or should I go into the panel and restore default and recreate the ES3Type? What would be your recommended approach.
If you're modifying the ES3Type to work with a parametric constructor, you would need to manually make the modifications to the ES3UserType_ file.
It seems that ES3 handles all this by itself if I have a parameterless constructor. Is this correct?
That is correct.
Well, I was trying to add an object without a parameterless constructor and I had to add it through the Types panel. The types panel created the script which is prefixed "ES3UserType_". After that, the script has an error because is trying to instantiate the object without parameters, which makes sense, and I have to add the default instantiation. Everything that I just mentioned happens inside ES3UserType, not ES3Type. And the methods I mentioned are within ES3UserType that it's asking me to change. Or am I doing something very wrong here?
The ES3UserType file is an ES3Type. Consider them the same thing.

All the best,
Joel