Hi, I have a widget component in my player character, set in world space and not visible, with a widget in it that I can interact with (has Receive Hardware Input on).
I’m using a keyboard event to “toggle visibility” of the component, which works for making it visible, but once I set Input Mode to UI Only, I cannot make the component INVISIBLE anymore. I assume because it doesn’t receive input anymore.
So what’s the proper way to toggle the component on/off? Thanks.
Many ways depending how you want your game to act during that minute to minute interaction.
I am assuming game is not paused but controls cut type of situation where this menu comes up.
Thus best and simplest way to do it is to listen input event from the UMG as close action.
Since this is visibility change is coming from you player character, when widget becomes active you can listen OnWidgetVisibilityChanged and register your close function over there as visibility (assuming you not destroying widget but making visibility changes)
1 Like
I’m not sure I understand what you mean. You mean having something like this in my component in the player character:
And then this in the widget:
Still doesn’t work because once I Set Input Mode To UI Only, the key press in the component in the player character won’t take the input anymore.
The idea was to have all the opening/closing functionality in the component. I was hoping there was a way to do that.
I have an input dedicated for in game menu.
Its defined in input mapping context for one device keyboard M
I have a widget component on my character (will not go into details of this since I don’t know what exactly you do, however be carefull with its performance)
In the beginning its invisible, upon player presses open map action,
- Widget Component is set to visible
- Widget Component’s User Widget is set to visible
- Input Set to UI Only and controls cut. Now player interacts with the widget.
On UMG there is nothing much, by default its collapsed and listens its visibility events, on visibility changed sets focus to Canvas just to be sure. Also notice on class defauilts widget is set to be focusable, without that inputs won’t be processed.
There is many event on every UMG UserWidget that you can override and one of them is OnKeyDown. I override this function.
I get the key pressed and compare it to OpenMenuAction Key
Also check if the widget is already visible.
If both of them correct, we process the event.
Set Visibility to Collapsed,
Give controls back to player.
Additionally you can set widget component to invisible as well.
As said not exactly knowing what you do, there are more advanced ways to control these events but simply with the solution demonstrated you can send player back and forth between umg and game world.
Let us know
1 Like