4. Scripting the Main Menu

In this step we will script the functionality for our Main Menu and load into game.

On this page

Page no longer needed.

Time to get our hands dirty and script the functionality of our Main Menu. At the end of this step we will be able to launch our game to the Main Menu, start our game as well as change the resolution inside the Options Menu.

  1. Open the MainMenu Widget Blueprint and click the Graph tab.


  2. In the MyBlueprint window, select the PlayButton then in the Details panel click the plus sign next to On Clicked.


    This will add a node to the graph that will execute whenever the button is clicked on.

  3. Add On Clicked Events for each of your buttons.


    We have arranged our Buttons in the graph to mimic the layout of our menu for clarity.

  4. Off the OnClicked(PlayButton), add a OpenLevel (set to FirstPersonExampleMap) node and a Remove from Parent node.


    The Level Name is where you indicate the name of the level you want to load (in our case the First Person Example map). The Remove from Parent node will remove the target Widget Blueprint from the viewport. It is set to target itself (which is the Main Menu Widget Blueprint that we want to remove from view after the level has loaded).

  5. Hold Ctrl and drag in the MainMenu and OptionsMenu variables.

  6. Drag off MainMenu and add a Set Visibility node. Set In Visibility to Hidden.

  7. Drag off and add a Set Visibility node. Set Invisibility to Visible

  8. Attach target to the OptionsMenu variable.


    Here we are turning off the Main Menu when the Options Button is clicked and turning on the Options Menu.

  9. Off each of the Settings Buttons add an Execute Console Command node.

  10. For the Command for each, use r.setRes XxY where X and Y are the dimensions to use.


    Above we are using the following settings: 640x480, 1280x720 and 1920x1080.

  11. For the Return Button, repeat step 6 but reverse the settings so Main Menu is visible and Options Menu is hidden.


  12. Off the OnClicked (QuitButton) add an Execute Console Command set to the command Quit.


  13. Compile and Save then close the Widget Blueprint.

  14. In the Content Browser, open the Main Level then open the Level Blueprint.


  15. Right-click in the graph and add an Event Begin Play node and connect a Create Widget (set Class to Main Menu).


  16. Connect an Add to Viewport node and add a Get Player Controller node.

  17. Off Get Player Controller, add the Set Show Mouse Cursor node set to True, then Compile and close the Blueprint.


  18. Open the First Person Character Blueprint inside the Content/FirstPersonBP/Blueprints folder.

  19. Following the Event Begin Play script, add a Get Player Controller then add a Set Input Mode Game Only node.


    This will turn off the cursor and set the input for the player to Game Only.

  20. Compile and close the Blueprint, then open the World Settings.


  21. Under Game Mode, set the GameMode Override to FirstPersonGameMode and change the Default Pawn Class to Character.


    Here we are assigning a Game Mode for this Map and changing the player's character to use the Engine Default Character inside of the playable FirstPersonCharacter Blueprint as we do not want the player to be able to run around and shoot behind the Main Menu.

  22. Click the Play Button from the Main Toolbar to play in the editor. To test the resolution options, select New Editor Window from the Play-in-Editor dropdown menu.

    Click the image above to play the video.

    We have now created a Main Menu that is functional and allows the player to quit the game, change resolution options or play the game (which loads up the specified level and transitions the player into gameplay).

In the next step we will add an in-game pause menu so that the player can pause gameplay or quit the game and return to this Main Menu.

Select Skin

Welcome to the new Unreal Engine 4 Documentation site!

We're working on lots of new features including a feedback system so you can tell us how we are doing. It's not quite ready for use in the wild yet, so head over to the Documentation Feedback forum to tell us about this page or call out any issues you are encountering in the meantime.

We'll be sure to let you know when the new system is up and running.

Post Feedback