LoadInto not working between scenes overriding ES3Settings

Discussion and help for Easy Save 3
Post Reply
JoseHawk
Posts: 25
Joined: Tue Sep 22, 2020 12:51 pm

LoadInto not working between scenes overriding ES3Settings

Post by JoseHawk »

Hello,

For the Nintendo Switch I had to reimplement my ES3 solution in order to work with cache due to the fact I cannot save directly into memory.

So for every new scene, I generate a new ES3Settings that I use in my save and load methods. Code looks like:

Code: Select all

        private void InitializeMemorySettings()
        {
            MemorySettings = new ES3Settings
            {
                location = ES3.Location.File,
                directory = ES3.Directory.PersistentDataPath,
                path = SaveFileName.MOUNT_NAME,
                encryptionType = ES3.EncryptionType.None,
                saveChildren = false,
                format = ES3.Format.JSON,
                prettyPrint = true,
                bufferSize = 2048,
                referenceMode = ES3.ReferenceMode.ByRefAndValue,
                serializationDepthLimit = 64
            };
        }
So for example, if I save my player and reload the same scene, first thing I do is to load into the scene player, the information previously saved. This works completely fine.

BUT when moving to a new scene, so the Player object that is in the hierarchy is a "new one", when trying load into it the previously saved information, I get the next error and my player values are not overrided:

Code: Select all

"Reference for Code.FunctiojnalLogic.Models.Player with ID 43433142314221 could not be found in Easy Save's reference manager. If you are loading objects dinamically, this warning is expected and can be ignored.
I tried changing the "referenceMode" to Ref, Value and RefAndValue, but it is not working.

Probably, as I am overriding my ES3Settings, something is missing. Could you identify what could be happening?

Thank you in advance.

Cheers.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: LoadInto not working between scenes overriding ES3Settings

Post by Joel »

Hi there,

If the Player object in the new scene is a 'new one' (i.e. not the same reference), then it would be impossible for Easy Save to know that the data you're trying to load relates to that object. In this case you would need to use ES3.LoadInto to tell Easy Save what object the data needs to be loaded into. If you are using ES3.LoadInto already, please could you replicate it in a new project with a simple scene in a new project and private message it to me with step-by-step instructions.

If it's the same scene, but you've just exited the scene and re-entered it, then I've not seen this behaviour before. If this is the case, as above, please could you replicate it in a new project with a simple scene and private message it to me with step-by-step instructions. Note that if the issue only occurs on the Switch I'm afraid we're not legally allowed to provide support due to Nintendo's licensing requirements.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
JoseHawk
Posts: 25
Joined: Tue Sep 22, 2020 12:51 pm

Re: LoadInto not working between scenes overriding ES3Settings

Post by JoseHawk »

Hi Joel,

Thanks for the fast reply. I double checked and with the cache, I am using Load, not LoadInto, so my fault :cry:

So my current method looks like:

Code: Select all

        public static T LoadFromES3<T>(string fileName, T @object)
        {
            var data= LoadDataFromMemory(fileName);
            var cache = new ES3File(data, SaveManager.GetSharedInstance().CacheSettings);
            
            return cache.Load(fileName, @object);
        }
But I would need to change it to look like:

Code: Select all

        public static void LoadFromES3_2<T>(string fileName, T @object)
        {
            var data= LoadDataFromMemory(fileName);
            var cache = new ES3File(data, SaveManager.GetSharedInstance().CacheSettings);
            
            cache.LoadInto(fileName, @object);
        }
Problem now is that I get the next compilation error (The type 'T' must be a reference type in order to use it as parameter 'T). It would be a big problem if I have to create a new method for every single object in my game (because it not only happens with my Player).

Do you have any trick for this? :mrgreen:

Thanks!
JoseHawk
Posts: 25
Joined: Tue Sep 22, 2020 12:51 pm

Re: LoadInto not working between scenes overriding ES3Settings

Post by JoseHawk »

Hello again Joel,

I just reply to myself. I think this code should do the trick:

Code: Select all

        public static void LoadFromES3_2<T>(string fileName, T @object) where T : class
        {
            var data= LoadDataFromMemory(fileName);
            var cache = new ES3File(data, SaveManager.GetSharedInstance().CacheSettings);
            
            cache.LoadInto(fileName, @object);
        }
I will let you know if I see any issue ;)

Cheers!
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: LoadInto not working between scenes overriding ES3Settings

Post by Joel »

Great, let me know how you get on :)

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply