Search
  • svcoyle

Saving the game & data persistence.


Before getting too far into the development progress, I decided I needed to go ahead and implement a saving and loading functionality for the game. In the past I have implemented autosave features any time players reached certain checkpoints etc. This made it a little easier to save cause you knew exactly where the player was in the game and only had to save enough data for that checkpoint. In Provenance I want players to be able to save whenever they want. No-one wants to repeat a puzzle after they solved it cause they had to log off before they reached the next checkpoint.


Luckily the way Provenance is structured allows for easy serialization and saving. Anything in the game that can change it state and needs to be saved is derived from a Base Entity class. Each entity registers itself with the scene manager singleton object for the level and when it comes time to save, each entity has a function to save its current state. Here is an example of the save function for a door.


public override EntitySaveState SaveEntity()
{
       _saveState = new EntitySaveState(EntityID);
       _saveState.enabled = this.enabled;
       _saveState.SetFlag("isOpen", _isOpen);
       _saveState.SetFlag("isLocked", _isLocked);
       return _saveState;
}


There is also a game-data class that holds global gameplay flags that gets saved as well as the player information (position, rotation, current inventory etc.).

It is a good idea to implement the save feature early before you find that the way your project is set up makes it a great deal more difficult to save out the data you need. Plus having the ability to save your game makes testing a lot easier as you can save your progress and load from there instead of relying on console commands to load a certain level and get needed inventory.


28 views0 comments

Recent Posts

See All