Hide Widget on Click

Hello!

I want to make simple thing:

  1. When I click on the some object, popup widget will be shown on the screen.

  2. When I click on buttons from this widget, some things will be done and widget will be hidden.

  3. When I click on empty place, just widget will be hidden.

Like this:
pic1
Press on (1), Hide (2).

But I cant do the third point. Since widget has no any mouse events.

Help me please :slight_smile:

Inside the UMG editor, click on a button of your widget, all the way down of the details tab is a “Events” tab with some events (lol), click on the “+” button of “OnClicked”. You’ll go to the Event graph, now just create the logic of that button (what will happen On Click) and make sure the last node is “Remove from Parent”.

The “Remove from Parent” is a node called to remove the widget from the viewport.

Hope that helps! :slight_smile:

It doesn’t help. Look at the top picture. I don’t want to press the button. I want to click in any empty place and hide the widget.

Oh! I see… Well… I never did any kind of logic related to that. The only way that I think of, is to add a transparent button to the empty screen space and when clicked, remove the widget from parent. But this would not be a good idea, because if the player click on another structure, it will just remove the widget. But I think that you could start with this logic and improve it.

Sorry if couldn’t help. Good luck!

Thank you :slight_smile: I had to change the logic behavior of the game.

Hey! I just thought to let you know that if you question has been answered; Please “Accept” it as answer; It saves time for us moderators and makes sure the questions that need attention are seen to as soon as possible! Thanks!

Hi, this is not answer :slight_smile: I still have not received a solution to the problem. This is just workaround for this question.

1 Like

Actually luccasclezars idea is an extremely good one, there is one more addition that you want to throw in to make this work. When you press the invisible button, run a linetrace from the mouse location to the world. use a line trace by channel with a custom channel set to “selectable”. If the trace returns a hit, check to see if that hit was a selectable object, if true, run the selection functionality that you’ll have set up for things like buildings. if it returns anything else, just remove the widget from your parent as suggested. This will let you remove the widget with the caveat that if there is a selectable object, you select that instead of just removing the widget.

In your level blueprint, look for mouse events, this will be a global mouse event, it will detect when there’s a mouse click. From there, you can add conditions to hide your widget

203520-mouse_event.jpg

#3 can be handled with an override of “On Removed From Focus Path”

I just achieved this using that node: