Issues with loading from a saved cache file

Discussion and help for Easy Save 3
Post Reply
NoctF
Posts: 3
Joined: Mon Oct 30, 2023 4:24 am

Issues with loading from a saved cache file

Post by NoctF »

Hello, I've been using Easysave for a while now, but have only recently switched to trying out loading via caching the data.

I've looked over a few resources and posts for an answer, including the performance guide, but I think I've reached my breaking point and decided to ask here on the forums for help since I needed this working as soon as I am able to get it to.

To make the explanation simple:

I have several save slots to load from and create a save file for them via cache like so:

Code: Select all

public ES3Settings saves; 

OnGameStartup(){
saves = new ES3Settings(ES3.Location.Cache);
}

Save(){
saveName = name + number;
ES3.Save<List<CustomClass>>("sceneIndex", CustomClassReference, saveName, saves);
ES3.StoreCachedFile(saveName, saves);
}
And then in a separate function I later load the save data based on saveName

Code: Select all

Load(){
saveName = name + number;
ES3.CacheFile(saveName, saves);
ES3.LoadInto<List<CustomClass>>("sceneIndex", saveName, CustomClassReference, saves);
}
This is a simplified version of the code, but I think it illustrates the idea as best as possible. Because I have scripts outside of the save/load script that access the save/load functions, and because these functions are separated, I opted to make to the ES3Setting into a public variable so it can be easily used. It is set at the beginning of each session during the game startup!

Typically, this works totally fine and the data is loaded and applied without issue. However, if I stop runtime and then attempt to load from the stored cache file after starting a new runtime session, said custom class will no longer be loaded properly and will result in a null/empty reference in my scene. I feel like I am misunderstanding how to properly utilize the stored cache file as I am using it for the faster save/load times.

Since it works if I save and then load within the same session, I imagine I might be screwing up somewhere without realizing it!

Any help would be appreciated, as this was a last minute bug I realized pretty late! Thank you very much for any response!
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Issues with loading from a saved cache file

Post by Joel »

Hi there,
said custom class will no longer be loaded properly and will result in a null/empty reference in my scene. I feel like I am misunderstanding how to properly utilize the stored cache file as I am using it for the faster save/load times.
This issue usually indicates that the reference you're loading no longer exists because it was created at runtime. This wouldn't be a caching issue because references are handled in the same way regardless of whether you're using caching or not. In this case I recommend taking a look at the Saving and Loading References guide, particularly the last section entitled "‘Reference could not be found’ warning":

https://docs.moodkie.com/easy-save-3/es ... eferences/

Also just to check, when you're calling ES3.LoadInto, is your CustomClassReference variable a List which already contains the same number of CustomClass objects as you're loading? See the LoadInto guide for more info if not:

https://docs.moodkie.com/easy-save-3/es ... -loadinto/

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
NoctF
Posts: 3
Joined: Mon Oct 30, 2023 4:24 am

Re: Issues with loading from a saved cache file

Post by NoctF »

Thank you so much for the response!
This issue usually indicates that the reference you're loading no longer exists because it was created at runtime. This wouldn't be a caching issue because references are handled in the same way regardless of whether you're using caching or not. In this case I recommend taking a look at the Saving and Loading References guide, particularly the last section entitled "‘Reference could not be found’ warning":
This is what I figured, however, this issue didn't start until after I had started using caching. Prior to this, I was just saving/loading everything normally and the references were always maintained, even through different sessions. This was initially why I figured it had to be related to either caching itself or how I was using it. Looking at the Load references guide, it might be possible that it is related to this as what I am saving/loading is a custom class with a variable that holds a gameObject that is instantiated at runtime, which is precisely what is not being loaded into data.

After testing, I tried to use the loading GameObject guide as well, I added a reference to the prefab to the ES3 Manager and even added a "ES3 GameObject script" to the prefab, but even then it did not become referenced.
Also just to check, when you're calling ES3.LoadInto, is your CustomClassReference variable a List which already contains the same number of CustomClass objects as you're loading? See the LoadInto guide for more info if not:
Yes! This is precisely the case. As mentioned, it always saves and loads perfectly fine in the session it is saved in. It is just the session following that, where all references are lost.



Thank you for the reply!
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Issues with loading from a saved cache file

Post by Joel »

Hi there,

If your GameObjects are instantiated at runtime then you would need to also save that GameObject, and then load it before anything which references it. Otherwise a GameObject with that reference ID won't exist between sessions.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
NoctF
Posts: 3
Joined: Mon Oct 30, 2023 4:24 am

Re: Issues with loading from a saved cache file

Post by NoctF »

Hello!

Yes, that is precisely what I attempted to. I saved and loaded said gameobject before the reference occurred, but even then the reference was not maintained properly!

Regardless, after a stressful few hours of testing and trying to make it work, I unfortunately just decided to revert back to the slower, non cache save/load method since it works albeit slowly, without issue for some reason!

Thanks for the help though!
Post Reply