Page 1 of 1
[SOLVED] Checkpoint Save
Posted: Thu Jan 16, 2020 9:41 am
by mschoenhals
Hi,
I would like to configure Quest Machine to save at checkpoints (which happen on scene changes). I would also like it to be an autosave (not managing slot numbers). Right now Quest Machine is saving when the game is stopped. How do I undo this? What's the best way to configure checkpoint saving? I added the Auto Save Load script to the Quest Machine prefab.
I'm also having difficulty removing the old save data. I have a menu system with a Start New Game Method. I tried using:
Code: Select all
PixelCrushers.SaveSystem.RestartGame("Forest");
But that didn't erase the old data.
I'm also getting 2 new console messages:
No SaveGameDataStorer found on Quest Machine and
No DataSerializer found on Quest Machine.
When I play the game, Quest Machine is starting with a Quest already completed.
How should I reset things?
Thanks.
Re: Checkpoint Save
Posted: Thu Jan 16, 2020 10:20 am
by Tony Li
Hi,
Remove the AutoSaveLoad component. This component saves the game when you quit and reloads it when you play again. It's useful for some mobile games but is generally not what players want for desktop, console, or web games.
To delete existing saved games, inspect your Save System GameObject. If you're also using the Dialogue System, then the SaveSystem component might be on the Dialogue Manager GameObject. Otherwise it might be on the Quest Machine GameObject or its own GameObject. If you don't have a Save System yet, you can create an empty GameObject named Save System. Add 3 components: SaveSystem, JsonDataSerializer, and PlayerPrefsSavedGameDataStorer. (You can use a different data serializer such as BinaryDataSerializer or a different storer such as DiskSavedGameDataStorer.) In the PlayerPrefsSavedGameDataStorer inspector, click Clear Saved Games.
To create a general checkpoint save, create an empty GameObject with a trigger collider. Add 2 components: TriggerEvent and SaveSystemMethods. Configure the OnTriggerEnter() event to call SaveSystemMethods.SaveToSlot(#), and specify a slot number for the checkpoint save.
If you want to tie this to a ScenePortal, put the TriggerEvent and SaveSystemMethods components on the ScenePortal GameObject instead. Clear the ScenePortal component's Required Tag field. Configure the TriggerEvent as above, and then add another entry to the OnTriggerEnter() event that calls ScenePortal.UsePortal.
Re: Checkpoint Save
Posted: Fri Jan 17, 2020 10:24 am
by mschoenhals
I followed the instructions and the journal info is saving between scenes. However, it's not loading when stopping and starting the game. I thought I might need to call a load command so I added the Quest Machine prefab to the main menu and then added to the button On Click() the SaveSystem/LoadGameFromSlot and then put in the number 1 for the slot number.
I thought it might be my Saving System so I reordered the triggers so that Quest Machine was loaded first. However, no Quest Info shows up. All my other save information for the player does save. If I inspect the PlayerPrefsSavedGameDataStorer it does show the Saved Game: SaveQuestInfo1.
Right now, I have added to the Quest Machine:
-Save System (Save Current Scene is not checked). I tried with it checked and it didn't make a difference
-JsonDataSerializer without Pretty Print checked
-PlayerPrefsSavedGameDataStorer with "SaveQuestInfo" as the Key Base, Encrypt is not checked
-Under save games I can see SaveQuestInfo1
The trigger event on the Portal must be working as there is a Save Game listed under PlayerPrefsSavedGameDataStorer. I have the following on my Portal:
-A Trigger Event with Player as the Tag Mask
-On Trigger Enter has SaveSystemMethods.SaveSlot and 1 is used for the slot number
-A SaveSystemMethods with nothing listed on Default Starting Scene Name
Does the Quest Giver need to have "Include In Saved Game Data" checked?
On the quest, I do have "Is Trackable" checked. It is tracked between Scenes so I think that part is configured correctly, is that right?
Re: Checkpoint Save
Posted: Fri Jan 17, 2020 10:38 am
by Tony Li
Hi,
The quest's "Is Trackable" checkbox just allows the quest to show tracking info in the quest HUD.
Tick the Quest Giver's "Include In Saved Game Data" if you want saved games to remember the quest giver's state (e.g., if it has already given a quest to the player).
When I replied before, I didn't realize you wanted to automatically load the last checkpoint save when the player plays the game again. To do this, add the Auto Save Load component back -- but untick all of the Save checkboxes; leave only the Load On Start checkbox ticked. Set Save Slot Number to the same slot number as your checkpoint saves.
Re: Checkpoint Save
Posted: Sat Jan 18, 2020 10:23 am
by mschoenhals
Ok, it is working now. If I'm on a scene and do a quest and then enter a portal, the saved game shows up under Player Prefs Saved Game Data Storer as "SaveQuestInfo1". If I hit stop and then play, the journal shows the current Quest info.
I had to remove the Quest Machine prefab from my MainMenu scene and I took out the On Click() event SaveSystem.LoadFromSlot trigger. Now when I click the button Load Saved Game, the saved quest info shows during gameplay, thank you.
How would I then configure my New Game button? If I remove the Quest Machine from the main menu, I no longer have access to PlayerPrefsSavedGameDataStorer.DeleteSavedGameData. I am able to click on Clear Saved Games and that does clear Saved Games.
Thanks.
Re: Checkpoint Save
Posted: Sat Jan 18, 2020 3:56 pm
by Tony Li
Hi,
You shouldn't have to remove the Quest Machine GameObject from your main menu scene.
But if you do keep it removed, just move the Save System components (SaveSystem, JsonDataSerializer, PlayerPrefsSavedGameDataStorer, and AutoSaveLoad) to a different GameObject, and put that GameObject in the main menu scene.
Re: Checkpoint Save
Posted: Sat Jan 18, 2020 6:57 pm
by mschoenhals
I put the Quest Machine prefab back into the main menu. But when I click on Load Saved Game, the saved game info is gone. That is, when I click on the Journal, the quest info is missing. However, when I look in the PlayerPrefsSavedGameDataStorer, it shows the saved game "SaveQuestInfo1".
If I go into another game scene and hit play, the saved game info shows up in the journal.
Any suggestions?
Re: Checkpoint Save
Posted: Sat Jan 18, 2020 8:11 pm
by Tony Li
Hi,
Is there perhaps more than one SaveSystem component in the main menu scene? There should be only one. It doesn't have to be on the Quest Machine GameObject, but it's okay if it's on the Quest Machine GameObject as long as it's the only one.
If you're playing a gameplay scene directly in the Unity editor, not coming from the main menu, and the journal shows saved game info, then you may have configured the AutoSaveLoad component to load automatically.
Here's an example:
QM_MainMenuSimpleExample_2020-01-18.unitypackage
To see it work, add Quest Machine's Demo scene to build settings, then play the MainMenuExample scene included in the package above.
Re: Checkpoint Save
Posted: Sun Jan 19, 2020 8:41 am
by mschoenhals
Hi Tony,
Thanks very much for your help. I couldn't get it to work by removing the save components and adding them to my Save System. I ended up adding a line of code to reset the playerprefs:
That does appear to work. I can go into the game, get some quest info, quit, and load from mainmenu. The quest data does showup. If I hit new game, the quest data is gone.
The example you gave me didn't load. There were some errors when I tried making a new unity project, load quest machine and then imported the example.
Thanks again for your help, much appreciated.
Re: [SOLVED] Checkpoint Save
Posted: Sun Jan 19, 2020 8:56 am
by Tony Li
Hi,
I'm glad you got it working.
I should have mentioned that I exported the example scene from Unity 2019.2, so it requires 2019.2 or higher.