Creating a Main Menu

How to create and script a main menu for your game.

Choose your operating system:

Windows

macOS

Linux

In this how to, you will learn how to create and script a main menu for your game.

If you started with the UMG UI Quick Start Guide, you can use the same project for this how to.

Creating a Main Menu

First bit of business is to create the layout of our Main Menu which we will do below.

  1. Open your MainMenu Widget Blueprint.

    You can follow the UMG UI Quick Start Guide if you need help creating a MainMenu Blueprint.

  2. On the Designer tab, drag and drop widgets from the Palette onto the Hierarchy to achieve the setup below.

    ![](Hierarchy1.png)

    For reference we have an Image, a Vertical Box with Text and 3 Buttons that have Text on our Canvas Panel.

    In the Hierarchy pane, you can search by widget class or name to help find your UI elements quickly.

  3. Select the Vertical Box in the Hierarchy then Right-click and Copy it.

  4. Right-click on the Canvas Panel and select Paste to paste a second copy of the Vertical Box.

    ![](Hierarchy2.png)

  5. In the new Vertical Box, Right-click copy a Button and paste it to create a fourth Button/Text widget.

    ![](Hierarchy3.png)

  6. Select the first Vertical Box and in the Details panel, rename it to MainMenu, check the isVariable option and set ZOrder to 1.

    ![](CreatingAMenu_3.6.png)

    We are naming the widget for clarity and setting it to a variable so that we can access it as well as setting the ZOrder so that it appears on top of our image which we will set in a moment.

  7. Select the other Vertical Box and in the Details panel, rename it to Options, check the isVariable option and set ZOrder to 1.

  8. Rename each of the Buttons as shown in the image below.

    ![](Hierarchy5.png)

    By updating the names of our buttons so that we know what each one does, this will make it easier to script functionality for them.

  9. Update each of the Text widgets as shown below via the Text section under Content in the Details panel.

    ![](CreatingAMenu_3.9.png)

    Here we are updating the text that is displayed on each of the buttons as well as the menu headers.

  10. Holding Ctrl select each of the Buttons then in the Details panel set a Tint color for Hovered and set each to Fill for Size.

    ![](CreatingAMenu_3.10.png)

    Here we are adjusting the size of all of our buttons as well as defining a color for the button to take when mousing over it.

  11. Select the Image in the Hierarchy then in the Details under Appearance and Brush, select a Texture, Sprite, or Material to use.

    ![](CreatingAMenu_3.11.png)

    If you want to use the same one as this guide, you can download it from here: Example Background Drag-and-drop the Example Background into Unreal Engine to import it (click Yes at any confirmation messages).

  12. In the Designer window, resize the image so that it takes up the entire layout.

    ![](Hierarchy9.png)

  13. In the Details panel for the Image, click the Anchor button and choose the fill screen option. You can also use a Scalebox to hold the image, which will ensure that the image scales and resizes appropriately to match the aspect ratio.

    ![](CreatingAMenu_3.13.png)

  14. Select both Vertical Boxes and Anchor them to the left-center position.

    ![](CreatingAMenu_3.14.png)

  15. Select the Options Vertical Box and set its Visibility setting to Hidden.

    ![](CreatingAMenu_3.15.png)

    We do not want options to be shown by default, we will tell it to be visible through script.

  16. Select the MainMenu Vertical Box and resize and position it as desired in the Designer window.

    ![](Hierarchy13.png)

  17. You can adjust the Font, Size and Alignment from the Details panel of each Text widget.

    ![](CreatingAMenu_3.17.png)

    You can experiment with these settings to get your desired effect.

  18. Setup your Options Vertical Box as desired then move it directly behind your Main Menu Vertical Box.

    ![](Hierarchy15.png)

    Since only one of these will be visible at a time, it is okay that they overlap one another.

With the visual layout of our menu complete, in the next step we will script the menu's functionality.

Scripting the Main Menu

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.

    ![](ScriptingMainMenu_4.1.png)

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

    ![](ScriptingMainMenu_4.2.png)

    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.

    ![](ScriptingMainMenu_4.3.png)

    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.

    ![](ScriptingMainMenu_4.4.png)

    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.

    ![](OptionsButton.png)(w:820)

    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.

    ![](Resolution.png)

    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.

    ![](ReturnButton.png)(w:820)

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

    ![](QuitButton.png)

  13. Compile and Save then close the Widget Blueprint.

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

    ![](ScriptingMainMenu_4.14.png)

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

    ![](EventBeginPlay.png)

  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.

    ![](FinishedLevel.png)(w:820)

  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.

    ![](PlayerCharacterBlueprint.png)(w:820)

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

  20. Connect the out pin of Set Input Mode Game Only to the Branch node.

    ![](ScriptingMainMenu_4.20.png)

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

    ![](ScriptingMainMenu_4.21.png)

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

    ![](ScriptingMainMenu_4.22.png)

    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.

  23. 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.

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).

This page was written for a previous version of Unreal Engine and has not been updated for the current Unreal Engine 5.0 release.