Save System Integration

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
rloft123
Posts: 22
Joined: Wed May 25, 2022 8:11 pm

Save System Integration

Post by rloft123 »

So I have an existing Save Load system (nothing too complicated) in my 2D game with an existing save and load button to trigger the functions. What they do is save the serializable objects I want saved, like in game time, player and npc position, inventory, and scene items (if picked up and destroyed, they won't reload).

I watched the save tutorial for Dialogue System and saw that save load system, and it seems pretty powerful. How should I go about incorporating the existing save system I have into the one provided by Dialogue System? Add the Save System component to my existing SaveLoadManager and add the SaveGame and LoadGame code into my existing code? Just curious if someone else has done something similar, not working with a fresh project when implementing Dialogue System. Thanks
User avatar
Tony Li
Posts: 22148
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save System Integration

Post by Tony Li »

I recommend going the other way. Set up the Pixel Crushers save system, and write a custom saver script that calls your existing Save Load system's code. The steps might look like this:

1. Download and import the Save System Prefabs package. (This is optional, but this way you don't have to set up the save system components yourself.)

2. Add the included LoadingScreen scene to your build settings.

3. Add the Save System prefab to your first scene. You can add it to other scenes, too, to make it easy to playtest those scenes directly in the editor. (Don't add a SaveSystem component to any other GameObjects in your scene, such as the Quest Machine GameObject.)

4. Add a DialogueSystemSaver component to your Dialogue Manager GameObject, and set a unique key value such as "ds".

5. If you want, you can replace some of your existing code with PositionSaver components to save the positions of the player and NPC.

6. For quick testing, add a SaveSystemTestMenu component. Then you can press Esc to open a test menu. The Dialogue System Extras page has a more robust menu framework if you want to use that for a main menu and pause menu that lets you save and load games.

7. Write a custom saver script: How To: Write Custom Savers
rloft123
Posts: 22
Joined: Wed May 25, 2022 8:11 pm

Re: Save System Integration

Post by rloft123 »

I attempted these steps, however my scene setup includes a PersistentScene that contains all my managers and NPCs, while my other scenes contain scene specific data like the grid of that scene. The non-PersistentScenes will load and unload depending on if I hit a box collider to trigger a scene transition.

I tried adding the Save System to the PersistentScene, Scene1 (that gets loaded after the game launches), and to both. Each time what happens on load is I get the load screen, but the PersistentScene is not staying, only the Scene1 is staying and the game breaks.
User avatar
Tony Li
Posts: 22148
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save System Integration

Post by Tony Li »

Only one SaveSystem component should be present.

Here are two different ways you can handle it:

1. Mark all of your PersistentScene objects as DontDestroyOnLoad. This will allow them to persist when loading other scenes.

2. Or don't use the save system's single-scene-changing methods: SaveSystem.LoadScene(), ScenePortral, or LoadLevel() sequencer command. Instead, additively load and unload your scene-specific-grid scenes using SaveSystem.LoadAdditiveScene() and UnloadAdditiveScene().
rloft123
Posts: 22
Joined: Wed May 25, 2022 8:11 pm

Re: Save System Integration

Post by rloft123 »

I've been going through the documentation a lot and cant seem to figure this out.

So here's my hierarchy structure:
-PersistentScene (contains my custom SaveSystem, see below why the normal SaveSystem isn't working for me)
-and the loaded in Scene1 at start

I added the SaveSystem.SaveToSlot method to my existing save functionality, and added that script to the SaveSystem object so my save button can point to that save method, which seems to save properly. However when I load using the SaveSystem.LoadFromSlot and then adding SaveSystem.LoadAdditiveScene("PersistentScene"); line right after it seems to load in two of my non persistent scenes (scene1), the persistent scene (so that works now) but the screen is black and nothing happens. I see them in the hierarchy but

I attempted just doing the SaveSystem to the PersistentScene like the guides say to do, but it immediately disappears when the game loads (same thing happens no matter what scene I add the SaveSystem to, I try PersistentScene and Scene1 that loads in first) and my Save game and Load game buttons lose the reference for their onclick
User avatar
Tony Li
Posts: 22148
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save System Integration

Post by Tony Li »

Hi,

If your PersistentScene GameObjects have DontDestroyOnLoad() run on them, they will automatically move to a new runtime scene named DontDestroyOnLoad. If this is the case, you don't need to worry about the SaveSystem unloading them.

---

I'm assuming your PersistentScene GameObjects don't have DontDestroyOnLoad() run on them -- in which case all of the notes below will apply to your setup:

Never use SaveSystem.LoadScene(). Also, UNtick the Save System component's Save Current Scene checkbox.

Instead, to stream in one of your location scenes, use SaveSystem.LoadAdditiveScene(). This works the same as Unity's SceneManager.LoadSceneAsync(scene, LoadSceneMode.Additive), except that it also applies saved game data to the GameObjects in the additively-loaded scene.

To stream that scene out, use SaveSystem.UnloadAdditiveScene(). This works the same as Unity's SceneManager.UnloadSceneAsync() except that it saves the scene's game data before unloading the scene.

To save the game, use SaveSystem.SaveToSlot(). However, since the Save Current Scene checkbox is unticked, you'll want to write a very small custom saver to save the names of the location scenes that are currently loaded.

To load a saved game, use SaveSystem.LoadFromSlot(). Since the Save Current Scene checkbox is unticked, this will not unload any scenes. You may want to unload your location scenes just prior to calling SaveSystem.LoadFromSlot(). In your custom saver's ApplyData() method, load the location scene(s) according to the names that it saved in RecordData().

Note that the SaveSystem GameObject is a "persistent singleton." That means it (1) survives scene changes, and (2) destroys any other GameObjects that have a SaveSystem component to ensure that there's only one. If you've assigned a UI Button's OnClick() directly to a SaveSystem GameObject, that SaveSystem GameObject may not exist after loading a saved game or changing scenes into the scene. Instead, add a SaveSystemMethods component to your UI Button and hook up the UI Button's OnClick() to the SaveSystemMethods component's method. SaveSystemMethods will automatically work with the current active SaveSystem instance without you needing to provide a direct reference to that instance.
rloft123
Posts: 22
Joined: Wed May 25, 2022 8:11 pm

Re: Save System Integration

Post by rloft123 »

Is there a way to just simply add the Dialogue part to my existing save? The existing save/load system I have along with the scene change controller I've implemented isn't really fitting well with this, at least with my experience and abilities, and I'd really need to restructure what I already have.
I got Dialogue System for its Dialogue and Quest functionality, which has worked very well. I just want to be sure I can save the Database, Actors, Variables, Quests, etc. I don't need the ability to save player location, scene, etc. Is this doable or no?

If that's not doable, or difficult, I may just start a new project, get this entire Dialogue System with the save system and scene management working in a skeleton project, and slowly work in my old project into that.
User avatar
Tony Li
Posts: 22148
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save System Integration

Post by Tony Li »

Hi,
rloft123 wrote: Tue Jun 07, 2022 10:09 amIs there a way to just simply add the Dialogue part to my existing save?
Yes: Dialogue Database-Only Save
rloft123
Posts: 22
Joined: Wed May 25, 2022 8:11 pm

Re: Save System Integration

Post by rloft123 »

That ended up working out for me, thank you.
User avatar
Tony Li
Posts: 22148
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save System Integration

Post by Tony Li »

Happy to help!
Post Reply