Page 1 of 1

Save/Load conversation state

Posted: Mon Nov 09, 2020 11:12 am
by purexlove
Hello,

I have a separate save system in my game, which saves game progress to a json file. I want to store conversation state and integrate it into existing save file. To do so I added DialogueSystemSaver component:
Screenshot 2020-11-09 174047.png
Screenshot 2020-11-09 174047.png (21.34 KiB) Viewed 245 times
After that, when saving the game I do:

Code: Select all

playData.dialogueData = dialogueSystemSaver.RecordData();
And finally, after loading and deserializing savefile I do:

Code: Select all

DialogueManager.Instance.StartConversation(scenarioInfo.conversationName);
dialogueSystemSaver.ApplyData(playData.dialogueData);
But it doesn't change conversation (it stays in default, initial state). Am I missing something? I took a look at my json savefile, and conversation data string is in place and looks perfectly fine. So my guess is that I'm not setting dialogue system state properly.

Re: Save/Load conversation state

Posted: Mon Nov 09, 2020 2:53 pm
by Tony Li
Hi,

You can save two kinds of state:

1. The values of the Dialogue System's variables, quest states, etc.

2. The state of the currently-active conversation (if one is active).

What do you want to save?

If you only want to save #1, remove all of the ***Saver component(s). Instead, use PersistentDataManager.GetSaveData() and ApplySaveData() to get the data as a string:

Code: Select all

playData.dialogueData = PersistentDataManager.GetSaveData();
and

Code: Select all

PersistentDataManager.ApplySaveData(playData.dialogueData);

If you also want to save #2, set up the Dialogue System's full save system by adding these components to the DialogueManager: Save System, Json Data Serializer, PlayerPrefs Saved Game Data Storer (required to avoid warning but won't be used), Dialogue System Saver, and Conversation State Saver. Then use PixelCrushers.SaveSystem.RecordSavedGameData() and ApplySavedGameData():

Code: Select all

playData.dialogueData = SaveSystem.Serialize(SaveSystem.RecordSavedGameData());
and

Code: Select all

SaveSystem.ApplySavedGameData(SaveSystem.Deserialize<SavedGameData>(playData.dialogueData));

Re: Save/Load conversation state

Posted: Mon Nov 09, 2020 6:10 pm
by purexlove
I need both variables values and currently-active conversation state. This should do the job, thanks a lot!

Re: Save/Load conversation state

Posted: Mon Nov 09, 2020 7:13 pm
by Tony Li
Glad to help!