How to remove UI widget when focus lost?

Hello!

I want a widget (in this case a button) to disappear when clicking somewhere else on the screen but on the button. I’ve tried using the event “Event On Focus Lost” and then the node “Remove from Parent” targeted self (see image below).

90717-aaaaaaa.jpg

However, with this setup, the widget does not disappear when clicking somewhere else on the screen.

Does anyone have any advice how to set up this?

Thanks in advance,
/Accel

You’re going to want the Set Visibility node that uses the ESlateVisibility Enum.

90730-widget.jpg

Removing from parent removes the parent/child relationship, but does nothing in regards to showing or hiding something. After you hide it, you can destroy it, but I would advise against it as you may want to use the widget later. If hidden, widgets do not demand draw calls, and you will not see a performance hit.

Thanks for your answer.
However, that doesn’t work for me. Did you try your soloution when connected to the event? And shouldn’t the “Set Visibility”-node be targeted as self, since I want the whole blueprint to dissapear?

/**
* Removes the widget from its parent widget. If this widget was added to the player’s screen or the viewport
* it will also be removed from those containers.
*/
UFUNCTION(BlueprintCallable, Category=“Widget”)
virtual void RemoveFromParent();

The documentation states clearly that it will be removed from the player’s screen/viewport as well. When I tested it was removed as expected.

Thanks for your explanation undercover. That is what I suspected. When I use “Remove from Parent” in other events it’s working fine, but it does not work with the event “On Focus Lost”! :frowning:

I had a similar problem, which I solved by adding a lower z-order border to the whole screen, then assigning an on-click event to that. The OnFocusLost seemed to not work for me.