Save/Load conversation state

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
purexlove
Posts: 5
Joined: Fri Nov 06, 2020 1:40 pm

Save/Load conversation state

Post 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 241 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.
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save/Load conversation state

Post 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));
purexlove
Posts: 5
Joined: Fri Nov 06, 2020 1:40 pm

Re: Save/Load conversation state

Post by purexlove »

I need both variables values and currently-active conversation state. This should do the job, thanks a lot!
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save/Load conversation state

Post by Tony Li »

Glad to help!
Post Reply