How to detect when loading is done?

Discussion and help for Easy Save 3
Post Reply
newjohnny
Posts: 12
Joined: Thu Jan 31, 2019 1:00 am

How to detect when loading is done?

Post by newjohnny »

I'm getting numerous null references from instantiated prefabs referencing each other so I would like to do a 2nd load pass, as suggested in other threads. I'm using the code below to load. How can I detect when this first load is finished?

Code: Select all

ES3AutoSaveMgr.Current.settings.path = file;
ES3AutoSaveMgr.Current.Load();
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: How to detect when loading is done?

Post by Joel »

Hi there,

Loading happens synchronously, so it’s finished immediately after the Load call is made.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
newjohnny
Posts: 12
Joined: Thu Jan 31, 2019 1:00 am

Re: How to detect when loading is done?

Post by newjohnny »

Ok good to know, however my scene takes about 10 seconds to load because it's huge and not fully optimized yet. Would two load commands still fully process in this scenario?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: How to detect when loading is done?

Post by Joel »

Hi there,

As they’re synchronous they will still process. The second won’t ever start until the first has completed.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Tanoshimi
Posts: 11
Joined: Thu Oct 07, 2021 4:25 pm

Re: How to detect when loading is done?

Post by Tanoshimi »

(Bumping this, instead of creating a new thread)

I'm having a similar issue, but I'm using AutoSave. It's set to load the scene in the Awake() function, but when I try to access the object's it's loading in the Start() function, I see they have not been instantiated yet. This doesn't happen often, maybe 1 in 10 times, but since my code checks to see if the objects exist and then creates them from scratch if they don't this is causing all of my saved data to be reset with default data at random intervals.

Is there a way to check to see if the AutoSave load is done? Or wait until it is? I mean, I can check to see if my GameObject is null, but I'm looking for a best practice here.

Currently, I plan on checking if the object is null, and if it is, checking to see if there's a save file. If there is, we can assume it hasn't finished loading. If there isn't, then we can assume this is the first run or the player deleted the file to reset the game.

Any suggestions?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: How to detect when loading is done?

Post by Joel »

Hi there,

As mentioned above, Easy Save works synchronously (unless you call it from your own thread), so it's done immediately after it's called. As all Awake() methods are called before any Start() methods, it would indicate that the issue isn't to do with timing but something else.

If it helps, you can manually call Easy Save using the code here:
https://docs.moodkie.com/easy-save-3/es ... -from-code

Easy Save will be finished on the line of code immediately after you call Auto Save's Save() or Load() method.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Tanoshimi
Posts: 11
Joined: Thu Oct 07, 2021 4:25 pm

Re: How to detect when loading is done?

Post by Tanoshimi »

So I wasn't sure if Start could run before all of Awake finished, I thought it would go as soon as Awake finished initiating commands. Good to know.

It appears that somewhere, sometime, it's saving after my data structure has destroyed the object, so it's not saving any data, then the next time there's no data to load.

At least, that's what I think is happening, because every time it happens I look at the save file and it's missing that chunk. I'll research it more. But it's hard to trace because it doesn't happen every time.
Post Reply