UMG Widgets: Hide/Show or Create/Remove?

I’ll be implementing my UI for inventory, character window, skill window, etc. soon - and i have a question:
Is it better to create all widgets (like inventory window or skill window) at once (at begin play) and then hide/show them when needed, or to create widget and remove when window is closed each time? For example:

Scenario 1 (Hide/Show)

  • Begin Play —> All widgets are created and hidden
  • User presses ‘I’ key, inventory window shows up by setting Set Visibility
  • User checks his Mighty Great Sword of Flames OP Edition +10, he’s happy and presses ‘I’ to close inventory - then it’s hidden by setting Set Visibility to Hidden

Scenario 2 (Create/Remove)

  • User presses ‘I’ key, inventory window shows up by Create Widget (InventoryWindow)
  • User closes the window and it’s removed by Remove From Parent

Same about all the pop-ups, like tutorial windows, some messages about game state, etc. Which approach is better?

It’s better to set it using the flipflop function for vice versa. Which in your case, “I” to open inventory and then “I” again to remove it.
Here’s an example from mine.


Change the key definition to keyboard “I” and the widget class to ur specific widget name.

If you want to save variables in your widget (edit : which you will certainly have for an inventory) , the way is to create them on begin play, create a reference ( from return value of create widget : promote to variable) and use this reference to add to viewport / remove from parent. In the example shown if you have more than one widget of this type, all widgets will be removed.

I disagree, in my project it removes the correct widget, even on multi-player. This works for my HUD elements and my Main Menu, granted I do not use any calls to “GetPlayerController” and all my code is multi-player enabled, but I am not sure if that would make a difference.

Yes, i didn’t see it was not the same picture and rectified. But if you have two widgets and want to remove one, it will not work. And this goes fine if widget has no info saved in needed.

Oh yes … 100% agree on that. I would not use this scenario for anywhere that I have more than one widget of the same class displayed. So your approach is the best one in that case. 8-}

Thank you for the answers, so i’ll probably go with Create all widgets on Begin Play + Make references to each one + then Add to Viewport / Remove from Parent when needed.

Yep. Also remember you can have an array of references to make your code a little more easier or use a struct with a unique identifier and then have an array of those instead. My suggestion is, get it working first as simply as possible and then optomise using arrays and structs if you feel you need to. 8-}

Good luck and let us know how it goes.

Why is it better? This question has been asked a million times but noone seems to be able to state why one approach is better than the other.
A test has been done showing that it is faster to Show and Hide rather than Unparent then re-Add to Viewport, but the common advice is to use the unparent approach. Why is this? What are the benefits of doing it this way opposed to just showing and hiding? Noone seems to know with any certainty.

It’s not really better (both work) but I guess the people in this thread use add/remove. I hide/set to visible instead and it works fine. I do use add/remove for temporary widgets like color wheels that are spawned when clicking on a color in a character creator widget. That way it can be spawned at the mouse click location.

One benefit of hide/show is that it does not cause the Construct event to be re-fired every time the widget it added to the Viewport.

If you use Construct to set up things like event bindings, or to dynamically add child widgets, then the hide/show approach will avoid having to “reset” the state of your widget. Otherwise you will end up with multiple bindings, duplicate children, etc.

Hello people ,

I am making a menu system.
So it has a main menu on which there is a play button on pressing which the levels screen loads up.
I have settings button in the levels screen for volume , music etc.
I want to know how should I approach this.

Edit : when one level ends and if the player wants to go to the levels screen so will the settings like music and sound be saved if I use the add/remove system??

this really helped me out @Sunnyseah

Dunno if anyone else does this but I think it’s more efficient or seems easier to me . Rather than creating and spawning multiple widgets for each Ui element I simply create one master widget and save a reference to that widget .

Then inside the widget I create each ui element on a seperate canvas or panel mark them as variables and give them a suitable name .

This way anytime I ever want to do anything ui related I only ever have to cast once to the stored master widget variable and because each panel is its own variable I can just show or hide the relevant ui needed by using the set visibility node .

Eg game begins I hide all panels as default set to hidden except main menu. Player presses a key I set main menu panel to hidden and set login panel to visible etc etc .

This way I don’t have to mess around creating multiple widgets and keeping track of multiple widget references or have to mess around with the remove from parent node etc . So far not ran into any problems doing things like this


i’m the same