Creating the main menu of the game
Hello, my name is Dmitry. I make computer games on the Unreal Engine as a hobby. When developing games, each of us is faced with the need to create a game menu in which you can make settings and also select game modes. In this article I will show how I solved this problem. As usual, all sources will be presented at the end of the article.
I packed all the code in a plugin. After you copy the plugin into your project, you will need to create a new HUD class, which should be a derived class from MainMenuPluginHUD. Through this class all control is carried out. Here are its settings.
TextScale, MarkColor, MarkLenght - Parameters responsible for displaying information on the radar.
SoundClass - There is a volume level in the settings, so here you need to put SoundClass to which the sounds you want to control will be attached.
MainMenuMapName - The name of the level at which the main menu will be displayed. That is, when loading this level, MainMenu mode will be enabled, while the remaining levels will include GameScreen mode.
Next is a list of widgets responsible for certain menu modes.
GameScreenWidget - Widget displayed on the game screen.
MainMenuWidget - The main menu displayed at the beginning of the game.
GameMenuWidget - Menu displayed during the game.
SettingsMenuWidget - Game settings menu.
KeyBindMenuWidget - Key Assignment Menu.
TitlesMenuWidget - Title menu.
ControlWidget - A screen describing the control of the game.
All widgets are located in the Content folder of the plugin, if you do not see them, the “Show Plugin Content” option is removed.
In addition, there are functions:
SetMainMenuMode - Set the current menu mode as a parameter receives EMainMenuMode.
GetMainMenuMode - Gets the current mode.
Game menu call
All menu modes are described in the MainMenuMode.h file. You need to add new modes or delete old ones there.
ButtonClick and GetButtonName - Required for the buttons to work. The buttons contain the EMainMenuPluginButtonType variable inside and when you click on the button or its spawn, the corresponding function is called with this parameter.
All buttons are described in the MainMenuPluginButtons.h file. You need to add and remove buttons there too.
SetPropertyInt, GetPropertyInt, GetPropertyNameInt - The same is true for the SIntProperty_Wiget widget. This widget is designed to display integers in the settings menu. In addition to the Int parameters, there are also bool and float.
All parameters are described in the MenuSettingsProperty.h file.
In addition to HUD, you need to create a GameInstanse class derived from MainMenuGameInstance. In order for Game instanse to work, you need to select it in ProjectSettings-> Maps & Modes-> GameInstanseClass. This will allow you to display the loading screen. (The loading screen does not work when starting the game in the viewport)
GameInstanse has only two parameters:
LoadingScreenWidget - A widget that displays when loading.
LogoMovie - The name of the video clip with the logo (without permission). The clip must be in the Content / Movies folder of your project in other folders, you can not put it. The video must necessarily have a resolution of 720p and a frame rate of 25fps, otherwise the UE will not be able to play it, this is strange given the fact that the Epics themselves upload the Logo on their website in 1080p and 60fps.
Link to download the plugin
I packed all the code from the HUD into an actor component, now there is no need to make my HUD derived from MainMenuPluginHUD. Just add the UMainMenuPluginHUDComponent component to the HUD.