Reset Lua variable on Checkpoint/Scene load
Posted: Tue Jun 11, 2024 6:16 am
Hi,
I'm using the DS Standard Scene Transition Manager together with the DS save and inbuilt quest system. I have also my own custom autosave/load on scene Transition and checkpoint save/load within scenes.
Now I started trying to author a simple kill x mobs quest. The scene holds enemy game objects each holding their own IncrementOnDestroy component. These are set up to work on Disable and to up a kill count. The quest has 2 entries that will be flagged as success if a certain threshold on the kill count lua variable is achieved. the scene also has a generic quest handler game object with appropriate DS triggers to react to the lua variable increment. The enemy game objects use setActive(false) when they recieve fatal damage, and the increment happens every time.
I now try to have the following behaviour: let's say the player has killed 3 enemies, thus having a lua variable value of 3.
Can I tell the DS to reset lua variables on scene load?
Can I tell the DS to ignore the setActive(false) calls after a checkpoint load? I've tried both SaveSystem.BeforeSceneChange() and PersistentDataManager.LevelWillBeUnloaded() but the doubling still happens, so it still recounts the enemies it shouldn't because they've already been disabled once.
I would be grateful for any hints.
I'm using the DS Standard Scene Transition Manager together with the DS save and inbuilt quest system. I have also my own custom autosave/load on scene Transition and checkpoint save/load within scenes.
Now I started trying to author a simple kill x mobs quest. The scene holds enemy game objects each holding their own IncrementOnDestroy component. These are set up to work on Disable and to up a kill count. The quest has 2 entries that will be flagged as success if a certain threshold on the kill count lua variable is achieved. the scene also has a generic quest handler game object with appropriate DS triggers to react to the lua variable increment. The enemy game objects use setActive(false) when they recieve fatal damage, and the increment happens every time.
I now try to have the following behaviour: let's say the player has killed 3 enemies, thus having a lua variable value of 3.
- Whenever the player reloads the level, it should be 0 again and all 3 enemies present and active.
- Whenever the player loads from a checkpoint both the lua variable should remain at the previous value of 3 and the already killed 3 enemies should stay inactive.
- Whenever the player reloads the level, the lua variable stays at 3 and the 3 enemies are active.
- Whenever the player reloads the checkpoint, the lua variable adds 3 for total of 6 and the 3 enemies are inactive.
Can I tell the DS to reset lua variables on scene load?
Can I tell the DS to ignore the setActive(false) calls after a checkpoint load? I've tried both SaveSystem.BeforeSceneChange() and PersistentDataManager.LevelWillBeUnloaded() but the doubling still happens, so it still recounts the enemies it shouldn't because they've already been disabled once.
I would be grateful for any hints.