Does a Widget stay in memory after removing it from Parent
I have created a widget that appears when a keyboard key is pressed and the game pauses. In there I have button that removes the widget and unpauses the game. with a simple "`Remove from Parent :Self`" Node, which lays inside a custom event called
I decided it would make sense to have the same key could also un pause the game, so I did the following:
At first, instead of the "`For Each Loop`" I had a "`Get index 0`" and it worked perfectly but only once!
My Question is this: does my PauseUI need something more to get destroyed or is "`Remove From Parent`" enough? If it is enough, why doesn't the "All widget of class" Table empty after it is removed?
the widget stays in memory when you use "Remove From Parent", there is no way to "destroy" it manually as far as I know.
What you could do, which is maybe a more elegant solution then using get-all-widgets-of-class, is to create a variable of the type PauseUI, when you click on the pause button you first check if the variable is valid (if something is stored in there), if not (first time clicking pause, it is empty) then you create a new widget of type PauseUI, assign it to the variable and add it to the viewport. When you want to remove it from the screen just use "remove from parent". Next time you want to pause, you check again if the variable is valid, now it is valid as you had previously stored the widget in there and you just add the content of the variable to the viewport.
I usually do this in blueprint so I don't have any code snippet to share for this functionality.
Let me know if it makes sense.
Follow this question
Once you sign in you will be able to subscribe for any updates here