So if there is a Button in an widget you can just add an “OnClicked Event”. What to do if you want to detect if the whole widget is clicked on in general? Or the other way around: Can you detect if the player clicks outside of the widget? So everything except the widget you are operating from.
I want to use this when multiple Widgets are added to the viewport to change the ZOrder to render the widget that is clicked on as the last one so that it is shown in the foreground. In addition i want to close widgets if the Player does not click on the widget surface but in the world etc…
So i’ve tested it but if you have a button as a child of another button or in general let it render over another button only the upper button can be pressed. So i can detect if my whole widget is clicked with the downside that this click on the widget cant be an interaction with the widget (you cant close it or use functions off of buttons etc.).
Is there any other way i dont have to face the downside of this ^ methode.
Override onMouseButtonDown for the whole widget. You could add a transparent border (more than one if you want an odd shape, or set the canvas to something other than NHT if you’re using one) set to Visible. Clicks within the widget will register and then you get to choose whether you want to Handle / Unhandle that input.
And if that widget has a button, the button will consume the click anyway.
I tested a little bit and it kind of works now. When the left mouse button is pressed anywhere in the widget it is rendered in the foreground and it doesnt consume the click so another action can take place. The problem is that widgets added after the first one (are rendered before because of the lower ZOrder value) dont register clicks. Only when the widget in the foreground is removed from parent they can be accessed.
Details on Blueprint:
In my MainUI_HUD if a new INFOHUD widget is created it adds the new widget to the canvas panel of the MainUI_HUD. In addition if no other widget of that kind is opened it sets a variable.
In the INFOHUD I used the override onMouseButtonDown to set the ZOrder of the INFOHUDs Border to 1. In addition with the functions “Reset ZOrder” and “Set on Top INFOHUD” i manage that only one widget is displayed on top.
The casting to CanvasPanel from the slot of the whole widget seems to be right cause the widget opened first is still on top even if a second widget is opened.
I dont know how to use the in and outputs of the overwritten function properly. My thoughts were that I added an “Unhandled” node to the output because i dont want to consume the inpput.