Custom Type Inner Class issues

Discussion and help for Easy Save 3
mdeim
Posts: 27
Joined: Sat May 09, 2020 7:31 pm

Custom Type Inner Class issues

Post by mdeim »

Hi Joel,

I'm having a lot of trouble with creating custom classes. Particularly for classes within a class.

So the game is almost complete and everything is coded, yet when I save using EasySave 3 there are issues saving a class within a class, so I created a custom class.

For example if this is the class...

Code: Select all

public class SomeManager : MonoBehaviour {
    [Serializable]
    public class SOME_INNER_CLASS {
        // other [NonSerialized] fields here...

        public string XToString = "1";
        public string YToString = "1";
        public string AToString = "1";
   
         // constructor
         public SOME_INNER_CLASS(float _XToString, float _YToString, float _Alpha) {
            ...some things going on here
        }

         // parameterless constructor created only for the purpose of EasySave3 to accept this class
         public SOME_INNER_CLASS() {
            ...some things going on here
        }
    }

    [Serializable]
    public AnotherClass() {
          // being used like this
          public SOME_INNER_CLASS Sizes = new SOME_INNER_CLASS(_XToString 1f, __YToString: 1f, _Alpha: 1f);
    }
}
I have two errors, one was about parameterless constructors, which I also read about in the doc, so I read in the forums one way to get around is to just create a constructor with no parameters, which I also added in the example above. Honestly, I wish I didn't have to create an empty constructor since it's not being used except for EasySave 3 to accept it since it's like a hack...But if there is no way around it unless it required a lot of work I rather not do it at this point.


Second, the second error I get is about namespace...
For example inside the ES3 Type generated script this would error(five same errors total):
Assets/Plugins/Easy Save 3/Custom Types/ES3UserType_SOME_INNER_CLASS.cs(12,53): error CS0246: The type or namespace name 'SomeManager' could not be found (are you missing a using directive or an assembly reference?)

Code: Select all

var instance = (SomeManager.SOME_INNER_CLASS)obj;
When I created this code I was still learning about C#, so I didn't use namespaces at the time, and at this point with everything referencing each other, it would be a big mess if I had to add a namespace. First I'm not 100% sure how to use it properly for ES3 Type cases, second is there any way to get around this namespace issue because I basically can't use Easy Save 3. Before ES3, I created my own save system which worked fine and doesn't have these issues, but I wanted to minimize little bugs that might crop up and have less code and I thought I could do that with ES3, but this is something that is unfortunately really stalling the project so I would really appreciate your advice on this.

Also, it's assuming that everyone created code the same way, ie, use namespaces which isn't always the case for everyone and I didn't know I had to keep this standard when I purchased the asset since it didn't mention it anywhere. Please let me know if I'm mistaken in thinking any of this, I'm just referring back to the information I received from the error.

Oh and I have a second more simple question, I always wanted to ask you about the float type. Does it have the same setback as if I didn't use EasySave3, ie. when you save a float it's not exact and the number can be unpredictable? That's actually why I'm still currently saving floats as a string.

I would appreciate any insight you have on these issues, thank you for your help.
mdeim
Posts: 27
Joined: Sat May 09, 2020 7:31 pm

Re: Custom Type Inner Class issues

Post by mdeim »

One way I got around this namespace issue, is adding the parameterless constructor while keeping the existing constructor and I deleted the custom type script. Seems ES3 will accept it as long as there is an empty constructor inside the class(thank god).

Then I saved as I normally would and it worked this time since the other values inside were native.

Unfortunately, I still have that issue with adding an empty constructor to the classes that needed for ES3 only and my question about floats.

Thank you for any advice.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Custom Type Inner Class issues

Post by Joel »

Hi there,

A parameterless constructor is required when automatically saving or loading otherwise it is not possible to automatically create an instance, as there's no way of telling which field relates to which constructor parameter.

If this isn't possible, you would need to follow the 'Manually adding support for a type' guide to generate an ES3Type file, and then modify this so that it reads the variables from the file and then manually calls your constructor. The ES3Type for Vector3 is a good example of a type which does this, which can be found in Plugins > Easy Save 3 > Scripts > Types > Unity Types > ES3Type_Vector3.cs. However, this would be more work than simply adding a parameterless constructor.

Regarding the second error you're getting regarding namespaces, this is a known issue in an earlier version of Easy Save, so deleting the ES3Type and updating from the Asset Store will resolve this.

Regarding floats, currently Easy Save stores floats to CSharp's serialisation specification, which is to 7-digits of precision rather than the full 9. However, I think we will change this in the next update to full precision. If you private message me your invoice number I'll be happy to send over an update which does this.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
mdeim
Posts: 27
Joined: Sat May 09, 2020 7:31 pm

Re: Custom Type Inner Class issues

Post by mdeim »

Hi Joel,

Thanks for the response!
I didn't realize there was an update since it was uploaded only a few days ago, I'm happy to hear that namespace issue was fixed. I'm ok with the parameterless constructor since yes, not knowing the fields is an issue I've also read about.

For the serialization issue, I'm not familiar with the 7 or 9 precision, what does that mean?

And what I meant was if I save it in Easy Save 3 will I have issues with instead of my float being 1.04 as I saved it, to sometimes save as 1.0445245, you know what I mean? When I tested it out, it seems to work fine right now but I just wanted to make sure with you so there won't be any future surprises. If this part is fixed and unrelated to the precision issue you mentioned then I am ok with waiting for the update. Please clarify.

Would you mind sharing generally when you typically update the asset so I know when to look out for it? Or is it just like whenever you have time?

Thanks so much ^_ ^
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Custom Type Inner Class issues

Post by Joel »

Hi there,

You're welcome :)

Regarding the precision, this means that it saves to 7 decimal places rather than 9. You would never get a situation where the saved value is more precise than the actual value (i.e. a float of 1.04 being saved as 1.0445245).

We're constantly working on updates for Easy Save, but we don't have any specific release schedule. As soon as the feature we're working on is ready and tested, we release it.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
mdeim
Posts: 27
Joined: Sat May 09, 2020 7:31 pm

Re: Custom Type Inner Class issues

Post by mdeim »

Hey,

With the update, my keys are saved but the data is now empty.
Was there anything changed, maybe something changed with the method syntax I'm not aware of?

And by the way, do you post more detailed updates like syntax updates and other issues that might crop up with these releases somewhere else too(https://assetstore.unity.com/packages/t ... 8#releases) is the only one I see?

Thanks
mdeim
Posts: 27
Joined: Sat May 09, 2020 7:31 pm

Re: Custom Type Inner Class issues

Post by mdeim »

Oh, I just saw your response. Ok thank you(about the float thing).
mdeim
Posts: 27
Joined: Sat May 09, 2020 7:31 pm

Re: Custom Type Inner Class issues

Post by mdeim »

The empty values is what I see from the new JSON pretty print, I wonder if that's related?

UPDATE:
Ok I just tested it out and the values are definitely there, but once they save with ES3File.Save("somekey", "some class value") and then synced later, they are not actually saved anymore after the update, even if I turned Pretty Print out, I am now reverting to old version and testing out if they are still there to make sure the issue is not on my end.
Last edited by mdeim on Sun May 17, 2020 7:57 pm, edited 1 time in total.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Custom Type Inner Class issues

Post by Joel »

Hi there,

Would you be able to create a new project which replicates this and private message it to me?

Also the releases log is where we will post changes. We don’t post detailed changes from our repo as this list can be quite long. However, we’ll never make a chance to the syntax which will break earlier versions.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
mdeim
Posts: 27
Joined: Sat May 09, 2020 7:31 pm

Re: Custom Type Inner Class issues

Post by mdeim »

Ok, I just verified that this is not an issue on my end by testing on my backup before the update, it worked. Then simply updating and the issue came up again.

I'm not able to send anything right now because I only have a few hours a day to work before my baby wakes up but I can explain more quickly here and maybe you are able to test it out this way, it's faster for me. If not, I will try to send something as soon as I can after I finish what I wanted to work on, I'll work from the old version for meanwhile.

I'm on Unity version 2019.3.13.
Basically I'm saving like this...

Code: Select all

    public class SOME_DATA {
        public readonly string Name = "";
        public readonly string SomethingElse = "";

        public SOME_DATA() {
            Name = SomeManager.Name;
            SomethingElse = SomeManager.SomethingElse;
        }
    }
    
    /// Then in another class in another file I create my cache, SyncStorage is called twice, pretty JSON is on/off same issue.
       static ES3File Cache;
       
       public static IEnumerator Save(...) {
               if (!ES3.FileExists(savefilepath)) {
                  Cache.Save<string>("Test", "Some Value");
                  SyncStorage(savefilepath); // calls Cache.Sync(savefilepath)
               }
               
               SomeClass.SOME_DATA Data = new SomeClass.SOME_DATA();
               
               Cache.Save("SomeData...", Data);
               
               SyncStorage(savefilepath)
       }
Post Reply