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!
ES3UserType parameterized contraints and ES3Serializable
-
- Posts: 39
- Joined: Thu Apr 01, 2021 4:53 pm
Re: ES3UserType parameterized contraints and ES3Serializable
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.
All the best,
Joel
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.
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.Would you mind expanding a bit more about "ES3Serializable", what's the difference with "Serializable" or "SerializeField"? When should I be using?
All the best,
Joel
-
- Posts: 39
- Joined: Thu Apr 01, 2021 4:53 pm
Re: ES3UserType parameterized contraints and ES3Serializable
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!
- 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
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.
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
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.
I'm afraid I don't understand the question.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?
This isn't an error in our guides.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
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
-
- Posts: 39
- Joined: Thu Apr 01, 2021 4:53 pm
Re: ES3UserType parameterized contraints and ES3Serializable
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 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?
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?Joel wrote: ↑Fri May 14, 2021 3:21 pmThis isn't an error in our guides.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
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.
Here is a pic
Re: ES3UserType parameterized contraints and ES3Serializable
If you're modifying the ES3Type to work with a parametric constructor, you would need to manually make the modifications to the ES3UserType_ file.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.
That is correct.It seems that ES3 handles all this by itself if I have a parameterless constructor. Is this correct?
The ES3UserType file is an ES3Type. Consider them the same thing.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?
All the best,
Joel