Page 2 of 3

Re: Continue last save/preview saves

Posted: Sun Oct 09, 2022 2:41 pm
by tabtaste
hey,

the solution does not work. foreach only find the desctrutable objects in the current scene and only when the object is not destroyed or deactivated.

greetings

Re: Continue last save/preview saves

Posted: Sun Oct 09, 2022 3:06 pm
by Tony Li
Good point. You'll want to cache the list of destructible keys when the scene starts. For example:

Code: Select all

private List<string> destructibleKeys;

void Start()
{
    destructibleKeys = new List<string>(FindObjectsOfType<DestructibleSaver>());
}

void OnTriggerEnter(Collider other)
{
    if (other.CompareTag("Player"))
    {
        destructibleKeys.ForEach(key => SaveSystem.currentSavedGameData.DeleteData(key));
    }
}

Re: Continue last save/preview saves

Posted: Sun Oct 09, 2022 3:26 pm
by tabtaste
yes thats right. But i want delete or reset all descructable saver in one moment/ scene from all descturable saver in the hole game. with this methood i only can delete thes from the actual scene right?

can i load the savedata delete all desturctable saver dater in hole save and save back or something?

EDIT:
Maybe is a outher way better: I want to save the descrutable status only for scene transition. i dont want to save or load this status. so wen i save or load the game all desctrutable object should delete there status.

I say it easyer. wen i save the game all enemy should respawn

Re: Continue last save/preview saves

Posted: Sun Oct 09, 2022 4:20 pm
by Tony Li
Hi,

It will help to be familiar with the SaveSystem API.

Assuming the SaveSystem component's Save Current Scene is ticked, you can do something like this:

1. Put a script like this on the SaveSystem GameObject:

RespawnEnemiesOnLoadGame.cs

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...
        SaveSystem.saveDataApplied += OnSaveDataApplied; // ...and when it's done applying save data.
    }

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

    void OnLoadStarted()
    {
        isLoadingGame = true;
    }
    
    void OnSaveDataApplied()
    {
        isLoadingGame = false;
    }
}
2. Make and use a subclass of DestructibleSaver that checks RespawnEnemiesOnLoadGame.isLoadingGame:

Code: Select all

public class RespawningDestructibleSaver : DestructibleSaver
{
    public override void ApplyData(string s)
    {
        if (!RespawnEnemiesOnLoadGame.isLoadingGame)
        {
            base.ApplyData(s);
        }
    }
}

Re: Continue last save/preview saves

Posted: Mon Oct 10, 2022 11:04 am
by tabtaste
hmm with this script alls enemys in the actual active scene respawn wen game is loaded.

i think my problem is that i will save the dead status between scene an on scene change the status is saved right?
so i think my only way to solve my problem is to write a function that get the savegame in slot and delete all infos about destrutable saver in it.

maybe i should right my own script for enemys for stay dead between scene and dont ever save enemy status with pixelcrusher.savesystem? did u have an idea ?

greetings

Re: Continue last save/preview saves

Posted: Mon Oct 10, 2022 11:30 am
by Tony Li
tabtaste wrote: Mon Oct 10, 2022 11:04 amwith this script alls enemys in the actual active scene respawn wen game is loaded.
Isn't that what you asked to do? What do you want to work differently?

Re: Continue last save/preview saves

Posted: Mon Oct 10, 2022 1:43 pm
by tabtaste
not exactly. i want to call a function wen i save the game. this function fill all health and energy from the player a should respawn ALL enemys in the whole game. when i change now a scene the enemys should spawn like bevor until i kill them again.

greetings

Re: Continue last save/preview saves

Posted: Mon Oct 10, 2022 1:50 pm
by tabtaste
my idia now is to store a keys from dead enemy in a dont destroy on load obect and delete all date bevore save the game.

do you think that can be work or have an better idea?

Code: Select all

    public void AddDeadEnemyToList(string deadEnemy)// call wen enemy die
    {
        if (!deadEnemys.Contains(deadEnemy))
        {
            deadEnemys.Add(deadEnemy);
        }

    }
    public void DeleteEnemyDataAfterSave()// call bevor every time save the game
    {

        foreach (var enemy in deadEnemys)
        {
            SaveSystem.currentSavedGameData.DeleteData(enemy);
        }
        deadEnemys.Clear();
    }

Code: Select all

    public void EnemyKilledAndSetOnRespawnList()// i add this script to every enemy that should respawn
    {
        DestructibleSaver saver = GetComponent<DestructibleSaver>();
        HoldEnemyDeadKeys.Instance.AddDeadEnemyToList(saver.key);
    }

Re: Continue last save/preview saves

Posted: Mon Oct 10, 2022 2:08 pm
by Tony Li
The scripts I suggested above should respawn all enemies when you load a game. Is this not working?

You can extend the scripts to also reset the player's health and energy.

Re: Continue last save/preview saves

Posted: Mon Oct 10, 2022 3:13 pm
by tabtaste
The Script from you above respawn all enemys in the current scene. Yes i can modify the Script to Also respawn when save the game but enemys in outher scenes dont respawn when i enter them after loading.