Widget Doesn't Close On Button Clicked


I am trying to get my widget to work so it closes when I press a button but, for some reason it doesn’t work. I am almost 100% sure I am doing it correctly.

If you put a breakpoint on “remove from parent,” does it get hit when you press the button?
(click “remove from parent” and press F9, then start the game.)

Also, are you sure there is only one copy of your widget in the viewport? Sometimes, multiple copies “accidentally” (ahem) get added, and removing one doesn’t make all of them go away. (As in: it’s pretty easy to build bugs into my code that creates a widget more than once.)


I am not entirely sure if it makes a difference in anything, but are you sure that removing the widget THEN doing some stuff with it not causing problems? I would put that node last.

Hello jwatte,

When I put the breakpoint on “remove from parent” it does get hit. I just realized I had it hooked up to an Event Tick. I put it to Event BeginPlay instead but now it doesn’t spawn (it is supposed to spawn when the player reaches a certain level in my xp system).

Generally, UIs shouldn’t manage their own lifetime, but instead something else (like the player controller) should manage the lifetime.

I have actors in my level that, in “on begin overlap” creates and adds the UI, and in “on end overlap” removes the UI.

It sounds like you want a boolean for “has shown XP UI” and, in the function that adds to the XP, check whether it’s greater than the threshold, checks whether the boolean is set, and if not set, create and add to viewport. You can still have the UI remove itself from the “done” button, as long as nothing else holds a reference to it. If the UI needs to animate, you can do that with animations within the UI, and with Bind functions; you generally don’t need a generic “tick” function to do that.

Hi jwatte,

Thank you for your reply, I have already figured out the problem though. Basically what I did was I hooked up a branch to an event tick and made the condition, “Did Player Level Up?” (for my xp system) and if it was true I made it create the widget and at the end I set “Did Player Level Up” to false and that fixed it. Thank you for your help though :smiley: