Page 1 of 1

How to know loading save is finished

Posted: Mon Jul 29, 2024 8:17 am
by windwalking
Hello!

Currently, I have an issue with the Save system. I can load and save my variables just fine. However when trying to rely on variables from the save file on Start functions, the save system did not finish loading and I only get the default values. Is there a way to make save system finish loading before everything else? Alternatively is there a way to know if the save system finished loading?

Re: How to know loading save is finished

Posted: Mon Jul 29, 2024 9:13 am
by Tony Li
Hi,

Yes, you can use SaveSystem.saveDataApplied. Example:

Code: Select all

using PixelCrushers; // Put at top of script.
...
SaveSystem.saveDataApplied += OnSaveDataApplied;
SaveSystem.LoadFromSlot(0);
...
void OnSaveDataApplied()
{
    SaveSystem.saveDataApplied -= OnSaveDataApplied;
    Debug.Log("Save data was applied.");
}
BTW, if you've set a Dialogue System Trigger to OnStart, you can change its Trigger dropdown to OnSaveDataApplied to tell it to wait for the save data to be applied before starting. If it's a regular scene start (e.g., entering play mode) and it's not applying save data, then it will act like OnStart.