Page 3 of 3

Re: Continue last save/preview saves

Posted: Mon Oct 10, 2022 3:48 pm
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));
    }
}

Re: Continue last save/preview saves

Posted: Mon Oct 10, 2022 4:55 pm
by tabtaste
Aaah okay got it. Great thanks allot !!!

Re: Continue last save/preview saves

Posted: Mon Oct 10, 2022 7:52 pm
by Tony Li
Glad to help! That should work, but if you have any questions let me know.