I have noticed that ApplyDataImmediate() is called even when I am using the SaveSystem to load a new scene, but not load a saved game.
Is that intended behaviour?
How to check if I am actually loading a savegame or not?
SaveSystem: ApplyDataImmediate called even when not loading a save game?
-
- Posts: 145
- Joined: Mon Nov 23, 2020 6:35 am
Re: SaveSystem: ApplyDataImmediate called even when not loading a save game?
Yes, that's intended behavior, but I'm open to feedback on it.
Here's the rationale: You load a new scene either by changing scenes (SaveSystem.LoadScene) or loading a saved game with 'Save Current Scene' ticked. In either of these cases, there may be some data that you want to restore immediately as soon as the scene loaded. However, in general, you want to wait 0 or more frames (the 'Frames To Wait Before Apply Data' value) to allow other scripts in the newly-loaded scene to initialize themselves before accepting save data.
If you're loading a saved game without 'Save Current Scene' ticked, you haven't loaded a new scene, so you don't need to wait. ApplyData() is called right away.
Here's the rationale: You load a new scene either by changing scenes (SaveSystem.LoadScene) or loading a saved game with 'Save Current Scene' ticked. In either of these cases, there may be some data that you want to restore immediately as soon as the scene loaded. However, in general, you want to wait 0 or more frames (the 'Frames To Wait Before Apply Data' value) to allow other scripts in the newly-loaded scene to initialize themselves before accepting save data.
If you're loading a saved game without 'Save Current Scene' ticked, you haven't loaded a new scene, so you don't need to wait. ApplyData() is called right away.
-
- Posts: 145
- Joined: Mon Nov 23, 2020 6:35 am
Re: SaveSystem: ApplyDataImmediate called even when not loading a save game?
I'm struggling with this a bit.
As I see it, using SaveSystem.LoadScene() will ALWAYS apply save data, correct? I should be using ResetGame() if I want to ensure that no save game data is loaded. That's how I understand what I see in the code.
I'm asking because I may be abusing the save system a bit. In my setup, there is exactly one scene per game - it's an RTS-like game. I auto-save to a fixed savegame slot, one per level. Players can continue a previous game or start a new one, but they can't have multiple save games for the same level.
As I see it, using SaveSystem.LoadScene() will ALWAYS apply save data, correct? I should be using ResetGame() if I want to ensure that no save game data is loaded. That's how I understand what I see in the code.
I'm asking because I may be abusing the save system a bit. In my setup, there is exactly one scene per game - it's an RTS-like game. I auto-save to a fixed savegame slot, one per level. Players can continue a previous game or start a new one, but they can't have multiple save games for the same level.
Re: SaveSystem: ApplyDataImmediate called even when not loading a save game?
Hi,
That's correct. SaveSystem.LoadScene() does this:
That's correct. SaveSystem.LoadScene() does this:
- Tell savers in the outgoing scene to record their states into memory (SaveSystem.currentSavedGameData object).
- Change scenes.
- Tell savers in the newly-loaded scene to retrieve their states from SaveSystem.currentSavedGameData if data exists.
- Clear SaveSystem.currentSavedGameData.
- Change scenes.
- Tell savers in the newly-loaded scene to retrieve their states from SaveSystem.currentSavedGameData if data exists (but there is none).
-
- Posts: 145
- Joined: Mon Nov 23, 2020 6:35 am
Re: SaveSystem: ApplyDataImmediate called even when not loading a save game?
Got it.
The part I don't get is how it gets currentSavedGameData.
I have one bug where I start a new game, but it loads save game data - and from a different scene. This is probably because I'm messing around with the SaveSystem, but I'm trying to understand what I'm doing wrong.
The part I don't get is how it gets currentSavedGameData.
I have one bug where I start a new game, but it loads save game data - and from a different scene. This is probably because I'm messing around with the SaveSystem, but I'm trying to understand what I'm doing wrong.
Re: SaveSystem: ApplyDataImmediate called even when not loading a save game?
SaveSystem.currentSavedGameData will stick around in memory until you clear it using SaveSystem.ResetGameState() or SaveSystem.RestartGame(), or if you overwrite it by loading a saved game using SaveSystem.LoadFromSlot().
If you're starting a new game, make sure SaveSystem.ResetGameState() or RestartGame() is getting called.
If you're starting a new game, make sure SaveSystem.ResetGameState() or RestartGame() is getting called.
-
- Posts: 145
- Joined: Mon Nov 23, 2020 6:35 am
Re: SaveSystem: ApplyDataImmediate called even when not loading a save game?
THAT is the part I totally didn't expect and caught me by surprise. Thanks, that explains everything.
If it wasn't my fault for missing it in the documentation, I think it should be marked there as an important info.
Re: SaveSystem: ApplyDataImmediate called even when not loading a save game?
Got it. I'll make that clearer in the documentation.