My Game Instance is proving to be my own personal hell on earth.
I am making a game similar to Crash Bandicoot. Instead of a warp room, the levels of the game are presented sequentially, so it appears as one giant world. Checkpoints are scattered throughout the game, and a special type of checkpoint marks a new level. The only real difference between a new level and a checkpoint is that levels can be selected from the load screen in case the player wants to play a level they’ve already beaten.
As the player progresses through the game, the Game State tracks what objects and enemies they’ve destroyed and collected, as well as the levels and checkpoints they’ve reached. When the player reaches a level or checkpoint, the data tracked on the Game State is set on variables in the Game Instance to preserve them in case the player dies.
However, if the player dies, the game will only load player stats from the Game Instance like health, lives, items collected, and the last checkpoint’s transform. It will not load the state of the level, which means that all of the objects and enemies the player has previously destroyed will not be removed from play. While the player will spawn at their last checkpoint, the game doesn’t remember what checkpoints they’ve reached.
The game will load the state of the level only if the variables are loaded from a Save Game Object. This is a problem because the game needs to be able to load these at checkpoints, which do not allow the player to save their game.
Probably the best way to track the enemies destroyed and items collected would be to have a map of arrays of actors no longer present in the scene (perhaps saving their GUID would be enough).
Then on load of the level iterate through the array and remove these actors.
The array would have to be saved in the save game.
Well if you will be going through the whole map on level load then just get the tmaps keys and iterate over them getting their values & do the appropriate actions.
This is what the system does when a game is loaded from a save game file. But I am trying to get the game to load this data from the Instance when the player dies and respawns.
The system is storing this information as it happens on the instance. Then it can be saved to a save game file at the end of a level. What’s messing me up is that I can’t retrieve it from the instance on respawn. Do I need to have like a cache save game file for this?