Hello. I created a main menu for my game and stuck with strange situation. How to correctly implement it in game? I’ve seen a lot of videos and there is very strange solution: create start menu widget in level blueprint (bind it to begin play) and destroy it by pressing “start” button. So if you’ll go that location you’ll get that menu again. I don’t like this solution.
I’ve created special blueprint for widget’s logic and create all the widgets and custom events there. I can’t use “begin play” event to create main menu because that blueprint is constructing again with changing level. So I’m looking for tips here. Maybe there is an event that activates only once in game session? Something like “Game start even”? Or there is another way?
The game instance activates only once per game session.
It’s also very useful because it carries on running, even if you load different levels.
There is no begin play, you use
Wonderful! Thank you. But how can I check if it works? I tried to play game as standalone process but there is no my menu.
My event to show menu in main widget bp:
My event in game instance:
I thought the problem may be there is no instance of my main widget bp, but I tried to create widget in game instance:
still no result.
Update: debug shows me, that cast failed when I’m trying to cast to main_hud. But I don’t understand why there is no start menu when I’m creating it in game instance?
No hud means nothing to attach the widget to. As simple as that…
There likely isnt a player during init yet. Which is why its failing to cast.
You can likely manually add the player or hud that you need / call the level load for the main menu or whatever else.
You have to consider that this is “normal”, you don’t want the whole game menu to be loaded in memory while you are playing, the normal behavior is to never return to the main menu.
Of course it all depends on your game.
If you really aren’t going to constantly go to the main menu, I’d like to show you something more elaborate.
I have a Mainmenu Player controller, scene and gamemode. As a note the settings are not part of the main menu as they can be called from the inGame pause window.
The map of the main menu is that I put the settings.
Hm, maybe you’re right and I just should create special level for menu. Can you please share with me your player controller’s and game mode’s settings? Or there is nothing special in it?
Player controller has nothing of interest I like to put it because it looks nice
The game mode I suppose will not be very different from the tutorials you have seen
For watever its worth:
Normally the main menu is different than the in-game menu but there is no law or linchmob that’s going to hold an indi game to this…
If you need to call/open the menu from wherever, then you should just bind it to the player controller as well.
What do I mean?
Well, in most game jam trash we don’t really have time to go into details with menus, so the same exact widget to start the game is either duplicated and repurposed after changing a few buttons (new game to start over or similar) or used as is as an in-game menu by also adding it to the player and giving them some input to toggle it on.
To me (and probably everyone really) what is most important is to provide seemless mouse/joypad/different input device functionality - which UMG doesnt let you do out of the box without overwriting and creating custom functions for “onkeydown”.
Dont know if this helps your conondrum on how to make the menu(s) work or just makes it worse… but hey, just keep in mind that everyone in games does UI wrong anyway