Page 1 of 1

Working with Corgi, and Checkpoints.

Posted: Mon May 09, 2022 5:22 am
by Jago1996
I am using corgi engines checkpoint system. But I'm having trouble resetting the conversations on loading those checkpoints.
If anyone has experience with this it would help a load.

What I mainly am trying to figure out is to be able to reactivate conversations based on what checkpoint I load. So that even if the convo has been ran and disabled. If the player dies the cut scene will be able to be ran again. I am trying make it work where depending on the checkpoint that's loaded, specific things are reset to there initial setups.

Another problem I'm having with it, is I'm trying to use corgies restart() command but through the conversation tree. Basically one of the cutscene options requires that you start back at the beginning of the level if you select it. But when I try and run that code through the dialogues event thing, the screen just freezes in the dialogue UI. I'm sensing that the event call happens before the UI has a chance to close and it's causing that issue. If that's the case, how would I get the code to be ran after the UI closes? Or is there a more elegant solution?

Re: Working with Corgi, and Checkpoints.

Posted: Mon May 09, 2022 10:57 am
by Tony Li
Hi,

First, use this technique to run the conversation only once: How To: Run Conversations Only Once

That link describes how to use a Dialogue System variable to remember that the conversation has already played.

For checkpoints, you'll want to use the save system to save the Dialogue System's state (e.g., variable values). To do this, set up the save system, and UNtick the SaveSystem component's Save Current Scene checkbox. You can use these steps:
  • Inspect your Dialogue Manager GameObject.
  • Add these 4 components: SaveSystem, DialogueSystemSaver, JsonDataSerializer, PlayerPrefsSavedGameDataStorer.
  • Inspect the SaveSystem component and UNtick Save Current Scene.
On your Checkpoint GameObject, add a SaveSystemMethods component. Configure the CheckPoint component's OnCheckpointReached() UnityEvent to call SaveSystemMethods.SaveToSlot. This will save the Dialogue System's state when entering a checkpoint.

Then make a subclass of LevelManager. Override the SoloModeRestart() method. Use your subclass in place of the base LevelManager. (See this page.) In SoloModeRestart(), call PixelCrushers.SaveSystem.LoadFromSlot(0):

Code: Select all

public class MyLevelManager : LevelManager
{
    protected override IEnumerator SoloModeRestart()
    {
        yield return base.SoloModeRestart();
        PixelCrushers.SaveSystem.LoadFromSlot(0);
    }
}
This will restore the Dialogue System's state.


To restart, add another Dialogue System Trigger component to one of that conversation's participants. (See Character GameObject Assignments for details about participants.) In the conversation, set a variable to indicate that the level should restart. Set the Dialogue System Trigger to OnConversationEnd. In the Conditions > Lua Conditions section, require that the variable is set. Then add an action to restart the level.

If you want to restore the Dialogue System to the state it was in when the player first entered the scene, you can add these steps:

1. Add a GameObject to the scene. Add SaveSystemMethods and DialogueSystemTrigger components. Set the Dialogue System Trigger to OnStart, and configure it to call SaveSystemMethods.SaveSlot. Specify slot 1.

2. When you restart the level call SaveSystemMethods.LoadFromSlot (1) or in C# call: PixelCrushers.SaveSystem.LoadFromSlot(1).

Re: Working with Corgi, and Checkpoints.

Posted: Wed May 11, 2022 3:27 pm
by Jago1996
I've managed to get this to work, thank you so much. This was very informative. I got it working and I'm excited to move on from here!

Re: Working with Corgi, and Checkpoints.

Posted: Wed May 11, 2022 4:04 pm
by Tony Li
Glad to help!

Re: Working with Corgi, and Checkpoints.

Posted: Mon Aug 21, 2023 9:14 pm
by Tony Li
If you're using the Menu Framework addon, you'll want to turn off SaveSystem.saveCurrentScene while reloading into the Corgi checkpoint. Then turn it back on after resuming at the checkpoint. Here's an example script:

Code: Select all

using System.Collections;
using UnityEngine;
using MoreMountains.CorgiEngine;

public class ExampleCustomLevelManager : LevelManager
{

    protected override IEnumerator SoloModeRestart()
    {
        yield return base.SoloModeRestart();
        if (PixelCrushers.SaveSystem.HasSavedGameInSlot(0))
        {
            Debug.Log("Turning off Save Current Scene and loading save data from slot 0");
            PixelCrushers.SaveSystem.saveCurrentScene = false;
            PixelCrushers.SaveSystem.saveDataApplied += OnSaveDataApplied;
            PixelCrushers.SaveSystem.LoadFromSlot(0);
        }
    }

    protected virtual void OnSaveDataApplied()
    {
        Debug.Log("Applied save data from slot 0. Turning Save Current Scene back on.");
        PixelCrushers.SaveSystem.saveDataApplied -= OnSaveDataApplied;
        PixelCrushers.SaveSystem.saveCurrentScene = true;
    }
}