AutoSave conversation/conversation state, for Mobile build

Announcements, support questions, and discussion for the Dialogue System.
bhavinsavajiyani
Posts: 42
Joined: Sun Jul 26, 2020 3:51 pm

AutoSave conversation/conversation state, for Mobile build

Post by bhavinsavajiyani »

Hello!

I have set up a scene, which has some conversations. Thanks to Dialogue System that it has been possible to create those conversations!
Things are working great.

But, I have a situation, where currently, the ongoing conversation ends, when "Back" button on Android device is pressed.
Once the conversation ends, the proximity selector of player still shows the attributes for triggering the conversation, but the conversation does not get triggered again, in the same, running instance.
Is there any way by which the conversation and it's states, get saved and loaded, from where the conversation has been ended?

Also I have some specific instances in the game, like a quiz, created using Dialogue System, where I cannot allow player to end the conversation or quit the game, from middle, unless that particular quiz is completed.
Like, once the quiz is started, player would have to complete the quiz. And if player decides to quit at any instance, after starting the quiz, a panel might pop up, stating that all progress would be lost if player quits and the quiz would have to be taken again, from start. The popup would include 2 buttons, one would quit the application (but player position and other data needs to be saved, and only variables or data of that particular conversation[ongoing quiz] should NOT be saved, before quitting. If any values of variables for that ongoing conversation, have been changed, then they should be cleared before quitting, so that when conversation is loaded again, they start from original states.). The other button can maybe take the player back to state of quiz conversation, which was reached before triggering of the pop up. What could be the possible approach for creating such a functionality?

I have also been reading the documentation and watched video tutorials as well. The thing is, video tutorial shows "manual saving & loading", to & from slots.
However, for the scope of my project, custom/manual saving to slots is NOT an option.
I came across "AutoSave", which I suppose is responsible for what I'm looking forward to accomplish. But I had doubts about how to set that up. Any suggestions on how to proceed with that?
How to save conversation states, configure conversations to NOT end when back button is pressed, or save the states if application is quit anyways?


Kind Regards,
Bhavin
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: AutoSave conversation/conversation state, for Mobile build

Post by Tony Li »

Hi Bhavin,

Add these components to the Dialogue Manager GameObject or whatever GameObject has your Save System component:
  • Save System
  • Json Data Serializer
  • PlayerPrefs Saved Game Data Storer
  • Dialogue System Saver
  • Conversation State Saver
  • Auto Save Load
On mobile, the player must always be able to close the app by pressing the "back" button. Depending on the platform, this can end the running instance of the app. However, by adding Conversation State Saver and Auto Save Load, it will save the game state (including the conversation state) when the player presses the back button. When the player resumes the app, it will restore the saved game state.

After you add the Auto Save Load component, check over its settings to make sure they will do what you want them to do.
bhavinsavajiyani
Posts: 42
Joined: Sun Jul 26, 2020 3:51 pm

Re: AutoSave conversation/conversation state, for Mobile build

Post by bhavinsavajiyani »

Thank You very much!
I would surely implement, what you suggested!

Edit: I did add all those components on Dialogue System Manager, as I had no Save System for any other game object! Currently, I did test it inside editor, but that isn't working! Would I have to build for mobile, in order to actually test it?
Also, I require player position to be saved. Also, would any extra components be required, to be added on Player Prefab?
Currently, in the editor, I interrupt the conversation, mid way, and it ends. Then at the same instance, when I start the conversation again, it starts from beginning. Stopping the scene and playing again, starts everything from beginning and player position isn't being saved.

Am I interpreting anything wrong?
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: AutoSave conversation/conversation state, for Mobile build

Post by Tony Li »

Hi,

It should work in the editor and in builds.

To save the player position, add a Position Saver component to the player prefab. Assign a unique key such as "PlayerPosition". Tick 'Save Across Scene Changes'. Leave 'Restore On Start' UNticked.

When testing in the editor, tick the Debug checkboxes on Save System and PlayerPrefs Saved Game Data Storer. When you stop and start play mode, the Console window should report that it's saving and loading the game. Check the Console window for these messages as well as for any warnings or errors.
bhavinsavajiyani
Posts: 42
Joined: Sun Jul 26, 2020 3:51 pm

Re: AutoSave conversation/conversation state, for Mobile build

Post by bhavinsavajiyani »

Hello.

I implemented what you suggested. Even checked Debug checkboxes on Save System and Playerprefs Saved Game Data Storer. But the Console window is NOT reporting anything at start or stop.

There are no other errors or warnings, being portrayed in the console, at runtime. My entire workflow is functioning as supposed to. No errors or warnings in the console. Yet, the conversation states and player position, start from beginning, after stopping once!

Scripts on Dialogue Manager.png
Scripts on Dialogue Manager.png (184.28 KiB) Viewed 592 times

Apart from these scripts, Dialogue Manager has following scripts attached on it:
  • Dialogue System Controller
  • Instantiate Prefabs
  • Input Device Manager
Edit: Do I have to specifically add any component(s) in respective conversations or Dialogue System Triggers, in order for them to get saved?
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: AutoSave conversation/conversation state, for Mobile build

Post by Tony Li »

Hi,

No, you don't need to add anything to the Dialogue System Triggers.

Set unique keys on the Conversation State Saver and Dialogue System Saver. A quick way to assign unique keys is to select menu item Tools > Pixel Crushers > Common > Save System > Assign Unique Keys.

Please post a screenshot of the Auto Save Load component's inspector.
bhavinsavajiyani
Posts: 42
Joined: Sun Jul 26, 2020 3:51 pm

Re: AutoSave conversation/conversation state, for Mobile build

Post by bhavinsavajiyani »

Hello.

I did set unique keys, as suggested.

Please find the Auto Save Load Component's attributes below:

Auto Save Load Component on Dialogue Manager.png
Auto Save Load Component on Dialogue Manager.png (151.54 KiB) Viewed 587 times
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: AutoSave conversation/conversation state, for Mobile build

Post by Tony Li »

With that Auto Save Load config, it should save when you exit play mode. Make sure your Console window isn't filtering out warnings, and that you're using the latest version of the Dialogue System. There was a bug in 2.2.11 with Auto Save Load.
bhavinsavajiyani
Posts: 42
Joined: Sun Jul 26, 2020 3:51 pm

Re: AutoSave conversation/conversation state, for Mobile build

Post by bhavinsavajiyani »

Ok. So previously, I was using version 2.2.8 of Dialogue System.
I re-imported the updated version (v2.2.12).
Now, the console does report activities. Thank You very much!

But I noticed a couple of things. My current workflow, involves fade in, showing an alert, and a waypoint pointing towards location to be reached by the player, at start. Player has to go to that location, which would further show one more alert when location is reached, find a NPC at given location and then talk with that NPC. The conversation would then begin.
I interrupted the conversation, after 2-3 dialogues were played. I stopped the game and started again. The player does get spawned at new location, but my scene events which were previously being shown at start, do get shown again. I get the same alerts, which normally get shown at start, and also the waypoint again points at the location to be reached. Ummm, any possible suggestions on how to avoid that to happen?
Also, the dialogue states are not being saved. The conversation starts from beginning, the next time. And I also have multiple quests in that particular conversation. Are any specifics required, during creation of conversations/quests, in order to make them start from where they had been stopped?

Also, the scene to starts directly, when played after stopping.
Is there any way by which the abrupt starting of scene could be prevented, and instead start maybe with black screen first, and then showing actual scene, after a while?

Edit: It also happened so, that when ongoing conversation was interrupted, it did get end. But I was not able to start that conversation again, in that same instance, as well as after stopping and starting again. I get spawned at same position, when game was stopped. Even the Proximity Selector of Player shows the relevant texts, but when I try to trigger the conversation, it does not get triggered.
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: AutoSave conversation/conversation state, for Mobile build

Post by Tony Li »

Hi,

The save system saves exactly what you tell it to save, and no more.
bhavinsavajiyani wrote: Sat Oct 31, 2020 12:34 pmThe player does get spawned at new location, but my scene events which were previously being shown at start, do get shown again. I get the same alerts, which normally get shown at start, and also the waypoint again points at the location to be reached. Ummm, any possible suggestions on how to avoid that to happen?
If you're showing the alerts using Dialogue System Triggers set to OnStart, then use the Dialogue System Trigger's Conditions section:

1. In the Dialogue Editor, add a Boolean variable to record that the alert was played. Its initial value should be false.
2. In the Dialogue System Trigger's Conditions > Lua Conditions section, require that the variable is false.
3. Select Add Action > Run Lua Code. In the Lua Code field, set the variable true.

Do similar for waypoints. Assuming the waypoint GameObjects are activated when turned on and deactivated when turned off, then one way is to add a Multi Active Saver to an empty GameObject. Assign the waypoint GameObjects to the Multi Active Saver's list. Saved games will record whether each waypoint is active or inactive.
bhavinsavajiyani wrote: Sat Oct 31, 2020 12:34 pmAlso, the dialogue states are not being saved. The conversation starts from beginning, the next time. And I also have multiple quests in that particular conversation. Are any specifics required, during creation of conversations/quests, in order to make them start from where they had been stopped?
If you exited play mode while the conversation was active, then when you play again it should resume the conversation where you stopped it. If this is not working, make sure the Conversation State Saver has a unique key.

However, if you play through the conversation all the way to the end, and then exit play mode, the saved game will record that no conversation was active, so it won't resume a conversation. In this case, use variables and conditions to decide where to jump back into the conversation when you start it again. This post has an example.
bhavinsavajiyani wrote: Sat Oct 31, 2020 12:34 pmAlso, the scene to starts directly, when played after stopping.
Is there any way by which the abrupt starting of scene could be prevented, and instead start maybe with black screen first, and then showing actual scene, after a while?
Add a Dialogue System Trigger set to OnStart. Select Add Action > Play Sequence. Set the Sequence to:

Code: Select all

Fade(in,2)
bhavinsavajiyani wrote: Sat Oct 31, 2020 12:34 pmEdit: It also happened so, that when ongoing conversation was interrupted, it did get end. But I was not able to start that conversation again, in that same instance, as well as after stopping and starting again. I get spawned at same position, when game was stopped. Even the Proximity Selector of Player shows the relevant texts, but when I try to trigger the conversation, it does not get triggered.
I don't have enough information to provide an answer. Examine the Console window for any errors or warnings. If that doesn't help, set the Dialogue Manager's Other Settings > Debug Level to Info. When you try to start the conversation, it will log the decisions that it makes to decide whether to run the conversation or not.
Post Reply