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.
asked Jul 31 '15 at 09:57 PM in Using UE4
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!
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!
answered Jul 31 '15 at 11:15 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here