Resuming and resetting the save file

The next step is to modify the functionality of the pause screen buttons so that they can properly resume the game or reset the save file on the player's machine. Click on the Reset All button, and in the Details panel, click on the + button next to On Clicked in order to create a new button Event. We will start by setting up the series of nodes needed to resume the game from a paused state, as seen in this screenshot:

In the Graph view, delete the Open Level node attached to the Resume button Event, and then connect the Remove from Parent node directly to the On Clicked (Resume) node. In addition to removing the pause menu when Resume is clicked on, we need to resume the game and disable the mouse arrow.

Create a Get Player Controller node. Drag a wire from the Return Value output pin of this node and attach it to a SET Show Mouse Cursor node. Ensure that this node's Show Mouse Cursor input checkbox is unchecked, and then attach the input execution pin of this node to the output execution pin of the Remove from Parent node. Finally, attach the output execution pin of the SET Show Mouse Cursor node to a SET Game Paused node, while ensuring that the Paused input checkbox is left unchecked. That will complete the functionality of the Resume button.

Now, turn your attention to the On Clicked (Reset) node. First, we will check for the existence of a saved game to be reset and, if one is found, we will use the player character to set the new saved data. The nodes needed to handle the save game branch and player character casting can be seen here:

Drag a wire from the output execution pin of the On Clicked (Reset) node, and then attach it to a Does Save Game Exist node. In the Slot Name input of this node, type BlueprintGameSave, ensuring that your spelling is consistent with the slot names given in the core logic within FirstPersonCharacter.

Next, drag a wire from the Return Value output pin and attach it to a Branch node. Attach the True output execution pin of the Branch node to a Cast To FirstPersonCharacter node. Finally, drag a wire from the Object input pin of the casting node and attach it to the Get Player Character node.

Now that we have the player character, we need to grab its Save Game Instance and reset the current round to the first round. We will then need to save this updated save game information to the BlueprintGameSave slot on the player's machine.

Start by dragging a wire from the As First Person Character output pin of the Cast To FirstPersonCharacter node and attaching it to a GET Save Game Instance node. Next, drag a wire from the output pin of this node to the Set Current Round node. Ensure that the execution pins between this node and the Cast To FirstPersonCharacter node are connected, and then set the input Current Round field to 1. Because the only data we intend to persist across play sessions is the current round the player is on, this is the only information we need to overwrite in order to represent a fresh save game.

Now, we need to ensure that our updated round data is actually stored in the player's machine. Drag a second wire from the output pin of the GET Save Game Instance node, and then attach it to a Save Game to Slot node. Connect the input execution pin of this node to the output execution pin of the SET Current Round node, and for the Slot Name input field, write BlueprintGameSave. The results of this should look like the following screenshot:

The final step for our Reset button is to reload the game map and remove the pause menu at the end of the sequence, as shown in this screenshot:

Drag a wire from the output execution pin from the Save Game to Slot node to an Open Level node. Then, look all the way back to the Branch node described earlier, drag a wire from the False output execution pin of that node, and connect it to the Open Level node. This will ensure that even if there is no save game data to overwrite, the button will still give some feedback by starting the game with the first round. For the Level Name input field of the Open Level node, enter either FirstPersonExampleMap, or the name of your Level if you have chosen to rename it differently from our example. Finally, connect a wire from the output execution pin of the Open Level node to a new Remove from Parent node. Congratulations! That concludes our work on the pause menu functionality. Create a helpful comment for the Reset button nodes, and then compile and save the Blueprint to finish.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset