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.
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.
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!
Actually 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