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!
Must LoadFromSlot twice to load variables
Re: Must LoadFromSlot twice to load variables
Hi,
If you're using the save system, hook into the SaveSystem.saveDataApplied C# event. Example:
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.
}
-
- Posts: 36
- Joined: Wed May 03, 2017 4:34 pm
Re: Must LoadFromSlot twice to load variables
Thanks for getting back to me.
It says that SaveSystem does not contain a definition for saveDataApplied.
Am I missing some kind of update?
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
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.
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.
-
- Posts: 36
- Joined: Wed May 03, 2017 4:34 pm
Re: Must LoadFromSlot twice to load variables
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
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:”
In particular, search for “Changed:”
-
- Posts: 36
- Joined: Wed May 03, 2017 4:34 pm
Re: Must LoadFromSlot twice to load variables
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.
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
Happy to help! I'm glad the update wasn't too bad.