Must LoadFromSlot twice to load variables

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
n_hagialas
Posts: 36
Joined: Wed May 03, 2017 4:34 pm

Must LoadFromSlot twice to load variables

Post by n_hagialas »

Hi Tony,

Had a question about loading variables from Lua when selecting to SaveSystemMethods.LoadFromSlot(0) using a button in a menu after Unity goes in and out of Play mode.

We have our game set up to read/load from Lua and the assign values to our player after reading them in from a save slot. Loading and assigning works fine when the game is running and then we Save -> then Load. However, if we save then press Play, and turn off Unity and then hit Play again and attempt to Load again, the values get set very late and the Player is unable to retrieve the values in Lua on time it seems. If we press Load again, then it seems to work, since the Lua variables have been loaded in from the first Load attempt. Is there an event we can listen to perhaps that says the Lua variables have been initialized after Load or is there some other way to handle ordering? Would appreciate any direction on how to handle this!

Thanks!
User avatar
Tony Li
Posts: 22135
Joined: Thu Jul 18, 2013 1:27 pm

Re: Must LoadFromSlot twice to load variables

Post by Tony Li »

Hi,

If you're using the save system, hook into the SaveSystem.saveDataApplied C# event. Example:

Code: Select all

SaveSystem.saveDataApplied += OnSaveDataApplied;
SaveSystem.LoadFromSlot(0);
...
void OnSaveDataApplied()
{
    SaveSystem.saveDataApplied -= OnSaveDataApplied;
    // your code here to assign Lua variable values to player.
}
n_hagialas
Posts: 36
Joined: Wed May 03, 2017 4:34 pm

Re: Must LoadFromSlot twice to load variables

Post by n_hagialas »

Thanks for getting back to me.

It says that SaveSystem does not contain a definition for saveDataApplied.
Am I missing some kind of update?
User avatar
Tony Li
Posts: 22135
Joined: Thu Jul 18, 2013 1:27 pm

Re: Must LoadFromSlot twice to load variables

Post by Tony Li »

Hi,

Are you on a really old version of the Dialogue System? It was added in version 2.2.7 (June 2020). Make sure you're using the PixelCrushers.SaveSystem component, in case your project has another script named SaveSystem, too.
n_hagialas
Posts: 36
Joined: Wed May 03, 2017 4:34 pm

Re: Must LoadFromSlot twice to load variables

Post by n_hagialas »

oh wow, we are on version 2.2.6, not sure how we missed this... What is the easiest way to update it? I did not see any options to update in engine.
User avatar
Tony Li
Posts: 22135
Joined: Thu Jul 18, 2013 1:27 pm

Re: Must LoadFromSlot twice to load variables

Post by Tony Li »

The usual way for Asset Store assets: back up your project, make sure the backup is good, then update through the Package Manager window. I recommend reading through the release notes, too: https://www.pixelcrushers.com/dialogue_ ... notes.html

In particular, search for “Changed:”
n_hagialas
Posts: 36
Joined: Wed May 03, 2017 4:34 pm

Re: Must LoadFromSlot twice to load variables

Post by n_hagialas »

Thanks Tony, we managed to update it, but we noticed our Dialogue Manager had replaced itself with a newer one and had to re-attach several scripts to it to get our game working again, no big deal thankfully.

We also were able to use the saveDataApplied event and it worked for us so thank you very much for that! No wonder I couldn't see it, we were behind on so many updates.
User avatar
Tony Li
Posts: 22135
Joined: Thu Jul 18, 2013 1:27 pm

Re: Must LoadFromSlot twice to load variables

Post by Tony Li »

Happy to help! I'm glad the update wasn't too bad.
Post Reply