Data saving properly but ApplySaveData() not working

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
CheMBurN
Posts: 5
Joined: Tue Apr 13, 2021 12:04 am

Data saving properly but ApplySaveData() not working

Post by CheMBurN »

Hi there, just bought the asset and it's pretty great!

Although, I hit a small snag when it comes to saving the game. I'm using ES3 to save my data and following this thread (https://www.pixelcrushers.com/phpbb/vie ... ata#p21632) I was able to set up the save system.

However, when calling my load function and ApplySaveData(), the variables just refuse to change. It's weird because through a debug.log of the save string on load() I can see the string reflecting the changes in the saved data (a bool "conversationFinished" changed to true) but it doesn't actually change the variable and the conversation continues as if I'm starting the conversation for the first time.

Weirder still, it appears to work when I save the bool as false, speak to the NPC (it gets set to true) and then load(). The variable get set back to false. But not the other way around.

It doesn't appear to be the way I've set up variable change (through the dialogue entry editor) as it works just fine when entering playmode (and through scene changes as well).

Also, the variable doesn't update in the variables list during runtime. (Although it's updated fine internally and the conditions work). Edit: Just learnt that the variables list doesnt update at runtime. However, it doesn't even show up in the Watches list either
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Data saving properly but ApplySaveData() not working

Post by Tony Li »

Hi,

Thanks for using the Dialogue System!

The post you linked discusses how to save only the Dialogue System's Lua environments (e.g., variables and quest states). If that's what you want, perfect! If you want to save the entire Dialogue System save system, set up the save system, and use an ESSavedGameDataStorer component instead of PlayerPrefsSavedGameDataStorer or DiskSavedGameDataStorer.

The Dialogue Editor's Variables page shows the variable values in the dialogue database -- that is, their design-time values, not their runtime values. At runtime, on the Watches tab you can select Menu > Add All Runtime Variables to show the runtime values of all variables. Alternatively, you can use the Variable Viewer window, which is a handy supplemental window for viewing and editing variables.

To address the issue you're describing: Is it possible that something is resetting the Dialogue System's environment after you've called ApplySaveData? For example, is it possible that some code block is calling DialogueManager.ResetDatabase() after calling PersistentDataManager.ApplySaveData(s)?
CheMBurN
Posts: 5
Joined: Tue Apr 13, 2021 12:04 am

Re: Data saving properly but ApplySaveData() not working

Post by CheMBurN »

Tony Li wrote: Tue Apr 13, 2021 8:56 am The post you linked discusses how to save only the Dialogue System's Lua environments (e.g., variables and quest states). If that's what you want, perfect! If you want to save the entire Dialogue System save system, set up the save system, and use an ESSavedGameDataStorer component instead of PlayerPrefsSavedGameDataStorer or DiskSavedGameDataStorer.

To address the issue you're describing: Is it possible that something is resetting the Dialogue System's environment after you've called ApplySaveData? For example, is it possible that some code block is calling DialogueManager.ResetDatabase() after calling PersistentDataManager.ApplySaveData(s)?
Hi Tony,

Thanks for your reply!

I've made a dumb mistake in my code (was sending an empty string to ApplySaveData()). Although I did realize that ResetDatabase() gets called after ApplySaveData() anyway. Regardless, the game is now saving the variables properly. Appreciate your time :)

Yeah I just want to save the variables and quests and stuff as I already have a system in place to save everything else. However, I've added the ES3 data storer like you've mentioned. (picture attached) A quick question - if I needed only save information pertaining to conversations (like who the player spoke with and what NPCs should say next, for which I've set variables for like "conversationsFinished"), saving the Lua environment is enough, correct?
Attachments
Save System.PNG
Save System.PNG (35.84 KiB) Viewed 219 times
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Data saving properly but ApplySaveData() not working

Post by Tony Li »

CheMBurN wrote: Tue Apr 13, 2021 12:46 pmA quick question - if I needed only save information pertaining to conversations (like who the player spoke with and what NPCs should say next, for which I've set variables for like "conversationsFinished"), saving the Lua environment is enough, correct?
ConversationStateSaver uses the complete save system. ConversationStateSaver records if a conversation is active at the time of the save; if so, it automatically resumes that conversation when loading. If you need to save this, then use the complete save system:

Code: Select all

string s= PixelCrushers.SaveSystem.Serialize(PixelCrushers.SaveSystem.RecordSavedGameData());
ES3.Save("DialogData", s, "DialogData");
and

Code: Select all

PixelCrushers.SaveSystem.ApplySavedGameData(PixelCrushers.SaveSystem.Deserialize<PixelCrushers.SavedGameData>(s);
Otherwise, if you only need to save variables, quest states, SimStatus (if you use it), and actor fields, you can bypass the save system and use PersistentDataManager.GetSaveData and ApplySaveData like you're already doing.
Post Reply