Give one key two functions/switch menus?

What I’m trying to do I believe is fairly simple, yet I’ve been stuck at it for over a week. It’s driving me mad. I’m trying to bring up two menus. InputAction Menu is “P” and Return is Backspace(btw this is in a HUD BP). When I press P it brings up a menu: Continue, Status, Exit Game. I want the player to be able to exit the menu by pressing Continue or hitting backspace. That’s set up. Now my problem is when I click the status menu, I get taken to the status menu. I want it so that when I hit backspace I return to the the pause menu with continue, and everything else displayed. I have no idea how to do that. In the picture this is what I’m on right now. Mind you I’ve redone this blueprint over a dozen times with dozens of functions, such as sequence, do once, isValid, is visible. The picture is just my final attempt, before now coming here and asking for help. I want it so that IF the status menu is open, then backspace will bring the player back to the pause menu, and IF the pause menu is also open, then pressing backspace again will close the pause menu and return you to game.

You should create a custom enum asset and use it as a variable in your HUD to have a reference to the current menu status. The enum could contain keys like “None”, “Pause” and “Status”. When you open or close one of the menus you can modify this variable accordingly. Using the Input Action event twice doesn’t make sense, istead you would want to use one, get your status variable and use a switch node, which will give you different execution pins for all statuses. So when you press backspace, the Return event gets called and then from the switch node you would want to remove the status widget when the variable is “Status” and remove the pause widget when the status is “Pause”.

Hope this helps!

Thanks for your answer, but to be totally honest I didn’t understand anything you said, like you were speaking a foreign language. :confused: I’ve never heard of enum so I’ve never used them. This is what I came up with. I know I’m not using it right, but I don’t know how to use it so this is all I could do.

What exactly am I supposed to do?

Just curious but why are you using HUD instead of pure widgets? Each new menu would have it’s own widget. On your main “Pause” menu widget, add the other widgets to the designer. Set the logic up so that when a particular button is pressed to go to another menu, you set visibility of your widgets accordingly. When “InputAction Return” is pressed, you again, set the visibility of the widgets accordingly to display what you desire. If you have multiple layers to your menus and “InputAction Return” is meant to go back successive menus then set the “InputAction Return” function in each outside menu (the ones added to the Pause Menu designer) and have the logic in those dictate which menu it returns too or if “InputAction Return” always goes back to the main Pause menu then just put a single line of logic on the pause menu. Doing it this way, all your menu’s will still be available to pull information from even if it’s set invisible, with your Pause Menu as the Parent, so to speak.

Also, as a side note, to save on resources, it may be best not to always create your widgets when you ask for them. Instead you should create your widgets all at once on game startup and store the instances in variables (I usually store mine on the player controller but other places could be Game Mode or Game State.) This way you can just “Add To Viewport” and “Remove From Parent” and never have any added processing overhead.

Hope this helps. Let me know if you need me to clarify my suggestions!

Oh, and you shouldn’t have 1 button be called in separate instances to perform separate tasks. You should just use a “sequence” node and in each pin of the sequence, run a branch to see if it’s the desired instance you are looking for. If it’s not then it will go to the next pin in the sequence. Or, if they run successively then no need to branch, just have the sequence node run in the order you need each logic to perform in.

I don’t know what you mean why use HUD instead of pure widgets. I am using HUD just because I heard that’s where you should do it when making menus. I do have pure widgets, I think, I’m not sure what that means. The Pause and Status menu widgets are umg. Is that what you’re asking? The problem I have is trying to get to another widget from a different widget, and returning to the previous widget. And when you say create them at game start up, you mean attach them to event begin play one after the other? Also visibility does not work on my widgets. I have tried set, toggle, get whatever visibility, but no widget ever shows up. You can’t even control visibility of the widget itself, only the parts that make it up like canvas panel, image, button, etc.

How do I add widgets to the designer. You mean my Pause menu widget’s designer tab?

Gimme a few minutes, I’m going to make a sample project for you

Alright, I created a very basic example in UE4 for you. No starter content, only 4 widgets, game mode and player controller BP’s exist. While I will admit that there is a better way to do this (it’s a little sloppy I was trying to do it fast and simplistic so you could easily understand what the basic premise is) but you will be able to see what exactly I was talking about with using “pure” widgets, which was to say widgets only rather than using the HUD (widgets implement the HUD anyway.) Here is the link:

Let me know if you have any further questions or if you have problems downloading this from dropbox. Hope this helps!

Yes, thank you, this is exactly what I wanted. I didn’t know you could add widgets to other widgets. I never noticed that “User Created” tab before. People told me to just always use add to viewport and remove from parent rather than toggle the visibility of widgets on and off, but this way works a lot better. I’ve been fine tuning it for my project for the past few hours.

I just have one question. You made it so that backspace triggers the Menu Return function, which returns you to the pause menu. Now I’m wondering how to make it so pressing backspace again returns to game. This was part of my original question. I kinda achieved it using a flip flop node, but of course the problem with a flip flop is it always starts from A then B. So say I press P to open the menu then hit backspace. If I want to open the menu again, I would have to press P twice.

Yeah the other way works too but to have menus that are part of a common scheme like your pause menus, it’s sometimes easier to do it like I did in there.

I thought you only wanted backspace to operate from the secondary menus but to answer your other question, all you have to do in order to have the backspace work in the main pause menu is add the same function as I did in the other menu graphs. You may want to extend the logic of the function in each widget though. By extend, all you need to do at the beginning of the function is check to see if that widget (the widget that has the function you are editing) is visible using a branch node. Since only 1 widget at a time is visible then only that widget that is visible will be made hidden. On the pause menu, instead of having the function setting another widget to visible, just remove itself from parent (like I did for the exit button.)

Generally speaking, it would be better to use an interface and link up your widgets and controller and have the message sent through that. By doing that you extend the reusability of the backspace for other things that may not be UI related but I wrote that just to keep it simple to give you a basic understanding of a new way to approach your UI’s.

I only have Pause Menu widget and Status Menu widget instead of your 3 Menus. Add the same function to the other menu graphs, so you want me to take Menu Return function (which is in my pause menu widget) and create a replica in the Status Menu widget?

And yeah I’ve never heard of interface either. It’s very difficult not being able to use the same button for a bunch of different uses. :confused:

Look up interfaces they are relatively easy when u see them. Should be some videos on it. And yeah, just copy the logic of the return function into each widget but have a branch to see if it’s visible before it tries to set it to hidden. If it’s not visible the that’s not the widget you want to set so it will skip the other logic of the function and move to the next widget to see if it’s visible, etc.

Well this is my project. It’s very sloppy. All the menus are just hastily put together so that I can learn how to properly use blueprints before getting serious and making actual menus. It’s meant to be like a JRPG menu. Where you press start or whatever button, then you’re taken to a menu with text displayed: Items, Skills, Options, etc, then if you click on one you’re taken to that menu, and if you hit circle (talking about playstation here) you get brought back to the previous menu.

I changed some things around trying to make it work how I want, and tried to add some of the things you mentioned but nothing seems to work. I’m wondering, if it’s not too much trouble, could you take a look and see if you can help me out some more?

I will take a look at it for you but it will be a day or two before I can look at it. Do me a favor and just go to my YouTube channel and send me a private message, tell me who you are in the message and I will give you my email address then. We need to take this conversation out of answerhub.

Go ahead and close this question out by accepting my answer (check mark below the arrows next to the original answer) and we can work on it one on one.

Thanks and sorry for the late reply. I just got so frustrated I decided to take a break from the engine, and I went back to Unity. Still not sure if I want to come back to Unreal though.