How to close widgets completely using remove from parent.

Hello helping heroes,

Im making a menu and closing widgets with remove from parent. But when I go back and forth a lot in my menu, it creates alot of pages and it never really closes them.
Naamloos12
They only go away when I open an other level. My game is not that big, is this bad or is it not that bad in a smaller game? I see no one talking about this in online tutorials.
Someone told me I can fix it with the garbage collector and if i get rid of the references. But how can I get rid of the references? I try to use soft references but my widgets keep having references to other widgets.
Maybe this is the wrong way?:


I dont know how to use soft references of widgets. This is the only way it connected and it kinda works but the widgets still have references to eachother.

-So is this a big problem of widgets not entirely closing? (I see no one talking about this, or is something wrong with my blueprints?)

-And if its a real problem, how can I fix this?

Thanks,

Remove From Parent works exactly like this, it removes the widget only visually, but it continues to be stored in memory, and will be removed after some time when the garbage collector timer runs, but only on condition that you no longer have references to the widget that you Remove From Parent.

This is not bad, but it’s not quite right…
It’s often easier to do this, but if you create a LOT of widgets in a short period of time (hundreds or thousands) - you may run out of memory before the garbage collector cleans it up.
It’s usually not a problem to just hide the widget instead of recreating it. The exception is if you need to reset all the defaults, but you can do that without recreating it. You’ll just need to write function for this.

Set the reference to “nothing” (call SetVariable on the reference and don’t connect anything)

When you use Cast or create a variable “reference to an object” you create a dependency on a CLASS (blueprint asset). This does not affect the garbage collection of INSTANCES of that class.

In your case, you can use CastToUserWidgetClass, and you will get rid of the unnecessary dependency.

1 Like