Continue last save/preview saves

Announcements, support questions, and discussion for Save System for Opsive Character Controllers.
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Continue last save/preview saves

Post by Tony Li »

Ah, I understand. In that case, you don't need the RespawningDestructibleSaver script I suggested above. Instead:

1. On your enemies, start the DestructibleSaver keys with "destructible_".

2. Edit SavedGameData.cs and add this at line 50:

Code: Select all

public Dictionary<string, SaveRecord> Dict { get { return m_dict; } }
(This addition will be in the next release of the save system.)

3. Use this script:

Code: Select all

public class RespawnEnemiesOnLoadGame : MonoBehaviour
{
    public static bool isLoadingGame;
    
    void Start()
    {
        SaveSystem.loadStarted += OnLoadStarted; // We want to know when SaveSystem is loading a game.
    }

    void OnDestroy()
    {
        SaveSystem.loadStarted -= OnLoadStarted;
    }

    void OnLoadStarted()
    {
        SaveSystem.sceneLoaded += OnSceneLoaded; // When loading game, we want to know when scene is loaded.
    }
    
    void OnSceneLoaded(string sceneName, int sceneIndex)
    {
        SaveSystem.sceneLoaded -= OnSceneLoaded;
        
        // After scene is loaded when loading a game, remove all keys that start with "destructible_".
        var destructibleKeys = new List<string>();
        foreach (var key in Dict.Keys)
        {
            if (key.StartsWith("destructible_")) destructibleKeys.Add(key);
        }
        destructibleKeys.ForEach(key => SaveSystem.currentSavedGameData.DeleteData(key));
    }
}
tabtaste
Posts: 16
Joined: Fri Oct 07, 2022 11:46 am

Re: Continue last save/preview saves

Post by tabtaste »

Aaah okay got it. Great thanks allot !!!
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Continue last save/preview saves

Post by Tony Li »

Glad to help! That should work, but if you have any questions let me know.
Post Reply