Best way to implement a level-chain

For constant level information, you can store that in a Table of custom Struct. Then for dynamic save information, you must create a SaveGame object, inside you can store any structs or primitive data. You cannot save a whole object, like your Player. So instead, you should pull the important information you want to save from any object, and store it in a struct or list of structs.

For example, if you want to save the progress of all your levels. Maintain an array of structs that hold that data in you GameMode, then send that to your SaveGame data before you save. Or just maintain it in your save object, just be sure to update it when things change, so it can be saved!

Below I’ll show how I store my linear game’s data:

  • My constant level data struct LevelStruct. In this, I store information that is shown on the main menu.

  • My Levels table Levels. Holds a list of my LevelStruct with different values for each level.

  • My dynamic save data FinishedLevels. In my game, I only need to store whether or not the player reached/completed a level. So it stores two maps of Level-ID’s paired with with whether or not they were reached or completed. This object is what is saved, and loaded.

  • I call this save function any time the values change, and I only ever have one persistent save. You could save multiple files in different slots.

  • Here’s how I load my save data. And if the location doesn’t exist, in my game I just make a new blank one. But your needs may be different. You may only want to create a new save data object, when a player starts a new game.