Hello! I am new to blueprints and appreciate all help:)
I am currently working on a menu with the setup listed under. The menu opens when you push M on the keyboard. I was wondering if there is a easy way to close the menu with the same button? Thank you so much in advance!
thank you so much for your respons! i really appreciate it i tried the second version, and this is how my blueprint looks like now. i will try your first method now. it did not work with the second, i dont think i did it right… the menu does not close. thank you again!
The isMenuVisible keeps track of the menu status. You need to add it yourself. There are other ways of keeping track of it but this is generic / versatile.
This way you create it only once, and then simply show / hide it instead. You can create the reference to a widget (here NewVar1) by right clicking the Return Value pin → Promote To Variable.
Not stupid at all, actually. It’s just an input processing thing.
Set Input Mode UI Only prevents the Player Controller from processing input - pressing M while this mode is active does nothing, the PC ignores it, as instructed. The input is processed in the widget instead since we’ve given it to the UI exclusively - Set Input Mode UI Only
You can have it processed by both (widgets go first, though) with Set Input Mode Game and UI node but if you’re making a first person shooter kind of game (we don’t know it here) you may not want to do this.
In order to make the same key work seamlessly (the way I think you want it to work,) you’ll need the following:
In the player (or wherever you press M to open the menu):
How long do you think this reference is valid? 5s, 60s until GC kicks in, 5 minutes, entire session? And what if something else needs to access it, it cannot.
Yep, UI only set in Player Controller. As soon as I click outside any visible component of the widget, it doesn’t fire the ‘onKeyDown’ function anymore. I assume it looses focus?
Well, just used onFocusLost → SetFocus (self). This is on my main menu. All good except the Quit Game button doesn’t work anymore, lol.
Using some print strings, I can see that, when I press Quit, onFocusLost fires.
The onKeyDown for closing the menu still works though.
Edit:
Apparently, everytime a child component of the widget gets focused (clicked buttons, in my case), the widget itself loses focus. Why is that useful is a mistery?
All you have to do is uncheck this:
on every child component. But I assume this will throw any keyboard/controller navigation of the UI out the window.
Another few good hours lost on figuring out something that should be trivial. I hope there’s good reasons for things to be designed like this.