Button programming

Now that we have completed player access to the pause menu, we will now focus on navigation within the main pause menu and its submenus. At this point, head back into your Pause_Main widget. Let us first create the navigation to Pause_Inventory. To do this, click on the Inventory button:

Button programming

Navigate to Details | Events | OnClicked and then press the + button:

Button programming

Clicking on the + button will automatically open the Event Graph of Pause_Main and also create an OnClicked event:

Button programming

The OnClicked event will work similar to our key bind in the previous section where we created something that allows us to press a key, which triggers an event that can then trigger a series of actions. Only this time, the OnClicked event is bound to our Inventory button and will only trigger when the user has left-clicked on the Inventory button. What we will want to do is, when we click on the Inventory button, have it create a Pause_Inventory widget that gets displayed on the screen. This should sound very familiar because we just did something like this with Pause_Main. So firstly, create a widget and attach it to the OnClicked event. Next, you will notice that the Class pin in the widget is empty so we need to select a class. You will be selecting Pause_Inventory since we want to create the inventory widget when the button is pressed:

Button programming

Lastly, just add this widget to the viewport so the user can see the inventory being displayed. In the end, your Blueprint should look like the following screenshot:

Button programming

If you test your pause screen now, you should notice that you are able to navigate to your inventory screen, but you are not able to navigate back to your main pause screen. This is easily fixable. Simply open your Pause_Inventory widget, press the Back button, navigate to Details | Events | OnClicked, and then press the + button:

Button programming

Just like our last button, the Event Graph will automatically open up and an OnClicked event for our button will be created; only this time, the event is bound to our Back button:

Button programming

From here, you will set the screen to remove itself by linking the OnClicked event to Remove from Parent.

When you are finished creating the Blueprint for your Back button, it should look like the following screenshot:

Button programming

You can now create the same setup for navigation from Pause_Equipment by making sure that when we click on the Equipment button, we create a Pause_Equipment widget and display it; when we click on the Back button in the Pause_Equipment, we navigate back to the Pause_Main removing the Pause_Inventory screen.

The next step is to allow the player to exit when they click on the Exit button. To do this, you must first create an OnClicked event on the Exit button within Pause_Main. Again, when you press the + button of OnClicked within the Design view, an OnClicked button for the Exit button will be created in the Event Graph:

Button programming

From here, you will set the screen to remove itself by linking the OnClicked event to Remove from Parent:

Button programming

Your screens should now navigate perfectly, but we are not done yet. The last thing you will notice is that the game is still paused when the pause menu is exited. We will need to unpause the game. This fix is very simple. Within the Pause_Main Blueprint, simply link Set Game Paused to Remove from Parent so that when the widget is removed, the game unpauses:

Button programming

You may notice that when leaving the pause menu, the mouse cursor is still present. You can remove the mouse cursor by simply creating a Set Show Mouse Cursor node and having it connected to your OnClicked Button_Exit event after you unpause the game, which would be similar to how you added a mouse cursor in the first place, this time making sure the checkbox within the Set Show Mouse Cursor node is unchecked meaning that Set Show Mouse Cursor is set to false, and attaching a Get Player Controller to it.

There you have it. We are now finished with the navigation of our pause menu and its submenus.

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

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