-
Notifications
You must be signed in to change notification settings - Fork 4
Save_System
The save system provides a rather simple way to save and load specific states of your game and Engine state.
Essentially, the save system is a series of points (orders) that make up a history. We can therefore go back and forward in time using save points.
You can add save points into your game using the Save Point
Order. When this point is loaded, the next order on that node is executed immediately. Other items such as variables and event handlers are also loaded back to whatever their values were upon saving. Additionally, players can use the save menu prefab to make their own save points and load through older ones.
You can use the example 'SaveGame' scene to understand the system in more detail by heading to:
Assets\LUTESampleExamples\Scenes\LUTEGames\SaveSystem
The Save Menu object can be seen In the root of the hierarchy window. This object controls the UI menu that the player uses to interact with the save system. The Save Menu is a singleton object that persists across scene loads, so you only need to add it once in the first scene of your game.
To add a Save Menu to your game, select LUTE > Create > Save > Save Menu
.
You can add a new save point as an order
to any given node:
When you start a new game, LUTE looks for a Save Point with the Is Start Point
property enabled and executes it. When loading a previously saved game, execution start at the relevant Save Point and ignores the start point (this only works when Load on Start
is enabled).
Note: the start event handler and games being loaded from a starting point save will both execute. If you wish to use the saving sytem then we suggest to not start your game using event handlers but with the saving start points.
Note: If you wish to start a game from a starting save point (say a main menu) but wish to load the latest save from this menu then please ensure that the Auto Save
toggle is false otherwise the game will save this point and then load into it leading to players being stuck in a loop! Other save points should make use of the auto save feature if you wish to create a 'Checkpoint' style of saving.
You often need to do some additional work when a saved game loads up to ensure the scene is in the correct state. E.g. The camera might need to be moved to the appropriate location or a certain music track played at this point in the game. An easy way to do this is via the Save Point Loaded event handler.
In the example scene, select the ‘Start Music’ Node in the Engine Window, and see it has a Save Point Loaded event handler. This will execute the Node when any of the Save Points in the Save Point Keys list loads. In this case we simply play the correct piece of music for this part of the game, but you could do any setup needed here.
The Save Point Loaded event handler will also fire when a matching Save Point order executes (if the Fire Event property is enabled). This allows you to place all the scene setup commands into a single shared Node which will be called when a Save Point order is first reached or when loading a previously saved game at that Save Point.
A frequent use of saving will of course be to load to the most recent save point upon returning to the game. However, most games do not start from a save point and will use a menu sytem. This is where the Load Game
Order is handy. Simply add this Order to a given Node and the Order will load the latest save point when the Node is called (say, from a menu click).
The key you typically input will be the name of the Node that the save is located on unless you specify a specific save point to load (this is useful for testing purposes).
If you toggle Return to previous node
then this will return to the previous node if there is no save data or point to load into.
Each Save Point can store the state of Engine variables at that point in time. You use a Save Data object to let the save system know which Engines are to be included in this. Note that only Boolean, Integer, Float and String variables are saved at present.
In the example scene, the Save Data object can be seen in the root of the hierarchy window. The Engine's property contains a list of the Engine objects to be saved in this scene.
To add a Save Data object to your scene, select LUTE > Create > Save > Save Data
. You can add as many Engines as you like to the list, but make sure that each one has a unique name or loading won’t work correctly.
If you are interested in extending the save system to support saving other types of data, you can either modify or subclass the SaveData component to achieve this.