How do I remove widget from the screen?

Hey, I’ve been working on my healing system, and the thing is I have 2 widgets that should be displayed, one for being heavily wounded and the other one for being lightly wounded, and one of these widgets should display continuously until player wound use MedKit but when I use it it does not remove the widget but health is changed. Here are the screenshots



I’m a beginner in this so I hope y’all understood the problem. In advance thank you for your help!

By the looks of it, your Check Health HUD is creating a new widget every time you call the event. Which causes you to have multiple widgets made within the viewport every time you press Q. Using the nodes “Create Widget” and “Add to Viewport” is making a brand new widget everytime, however you can use the node “Remove from Parent” to remove the widget!

I’d recommend restructuring your events like within the construction or begin play of your player character or player controller to create the two Widgets and set them to variables like you already have in the Check Health HUD event → then use the node from the widget references called Set Visibility and use the option “Collapsed” for both widgets.

Afterwards, change the “Check Health HUD” event to no longer create widgets and use the Widget variables you made to create the node Set Visibility on the widget. Now you would be able to show/hide widgets by either using the option “Visible” for showing or “Collapsed” for hiding.

2 Likes

Hi, thank you for your response, and its kind of worked but only 1 time, and afterwards nothing happens, did I miss something? Is there should be some sort of while loop?

(post deleted by author)

(post deleted by author)

Hey,

I would keep everything in a single widget and adjust visuals as required. If not, you can toggle visibility of widgets, hiding first one / displaying second one (or remove parent / add to viewport again, as long as your widget reference variable is not null/empty). You would create both widgets when game starts, but adding only the main one to viewport. When you need to switch to other one you would hide the first one and show the second one.
Maybe a widget switcher could work here too.

1 Like

I can, but it won’t look that good, because I have different images that beautifully represent the statement of the character in different ranges of HP, but thanks for suggestion :slight_smile:

Handle all of your UI in the controller class.
When you add a widget create a ref variable for it.

I use events for creating, loading and unloading widgets.

Health should be managed in the Player State. When health is changed call a controller event to update UI.

1 Like

Here’s a more robust setup.

2 Likes