Page 1 of 1

Must LoadFromSlot twice to load variables

Posted: Mon Feb 27, 2023 1:41 pm
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!

Re: Must LoadFromSlot twice to load variables

Posted: Mon Feb 27, 2023 3:48 pm
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.
}

Re: Must LoadFromSlot twice to load variables

Posted: Mon Feb 27, 2023 4:10 pm
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?

Re: Must LoadFromSlot twice to load variables

Posted: Mon Feb 27, 2023 8:31 pm
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.

Re: Must LoadFromSlot twice to load variables

Posted: Tue Feb 28, 2023 11:00 am
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.

Re: Must LoadFromSlot twice to load variables

Posted: Tue Feb 28, 2023 11:24 am
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:”

Re: Must LoadFromSlot twice to load variables

Posted: Tue Feb 28, 2023 12:46 pm
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.

Re: Must LoadFromSlot twice to load variables

Posted: Tue Feb 28, 2023 3:04 pm
by Tony Li
Happy to help! I'm glad the update wasn't too bad.