# UMG - Remove From Parent - still valid

**URL:** <https://forums.unrealengine.com/t/umg-remove-from-parent-still-valid/435585>\
**Category:** UI\
**Tags:** remove-from-parent, unreal-engine, bug-report, Widget, Blueprint, question, UMG\
**Created:** [October 13, 2018, 10:08pm UTC](https://forums.unrealengine.com/t/umg-remove-from-parent-still-valid/435585 "2018-10-13T22:08:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oolahk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Oolahk](https://forums.unrealengine.com/u/Oolahk)\
**Post date:** [October 13, 2018, 10:08pm UTC](https://forums.unrealengine.com/t/umg-remove-from-parent-still-valid/435585/1 "2018-10-13T22:08:59Z")

</div>

Hi folks,

I’ve been trying to figure out if this is new to 4.20.3 but when I Remove From Parent on a widget, or Remove All Widgets, they seem to be removed from the viewport, but remain in memory and also the variable is still valid.  
If i ignore it’s validity and Create Widget again I will have multiple versions of the same widget in memory - you can see this by dropping down the Debug Filter and seeing how many duplicates. This does not seem right at all. Imagine pausing the menu several times you would be using unnecessary memory storing duplicates. Is this a known issue to Epic? Anyone else having the same problems?  
I don’t remember having this problem in previous versions of ue4.

Thanks,  
Ming

---

<div class="post-metadata">

**Author:** ![llll\_Sabre\_llll](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@llll\_Sabre\_llll](https://forums.unrealengine.com/u/llll_Sabre_llll)\
**Post date:** [October 15, 2018, 10:58am UTC](https://forums.unrealengine.com/t/umg-remove-from-parent-still-valid/435585/2 "2018-10-15T10:58:39Z")

</div>

Hi Oolahk et al,

yes, a similar thing is happening to me right now.  
But firstly I do suggest that every time you create a new Widget you check if it exists already with the “Is Valid” check and then just use that one rather than create a new one. This at least stops the duplication.

My situation is similar, but is creating bugs: When aborting the game level, I am removing a HUD blueprint (“Remove from Parent”), and loading the menu map; but the code within the HUD is still firing (I have some HUD animations and so on that use delays, e.g. a countdown). So if the player quickly re-enters the game level again things occur out of order.

I can see a quick hacky way to fix this but how is it supposed to work?

I believe this is a related bug that was submitted a few years ago.  
[https://issues.unrealengine.com/issue/UE-22560](https://issues.unrealengine.com/issue/UE-22560)

It would be really good to hear what the intended procedure for this is supposed to be. I had assumed that Remove From Parent would stop all code running in that Widget. If not, what’s the best procedure for doing so? Does everyone Destroy widgets after a “Remove From Parent”? Is there a node that I’ve just not noticed for sorting this out?

Thanks,  
Sabre.

---

<div class="post-metadata">

**Author:** ![llll\_Sabre\_llll](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@llll\_Sabre\_llll](https://forums.unrealengine.com/u/llll_Sabre_llll)\
**Post date:** [October 15, 2018, 12:00pm UTC](https://forums.unrealengine.com/t/umg-remove-from-parent-still-valid/435585/3 "2018-10-15T12:00:59Z")

</div>

After more intensive Googling, I’ve found the info that’s needed. Here:

[link text](https://answers.unrealengine.com/questions/730495/widget-garbagecollection-not-working.html?sort=oldest)

So “Remove from Parent” and then “Collect Garbage” should fix both of our issues. (Providing you move your “Create Widget” into a function).

Testing now… hmm, my first attempt doesn’t work. Let me know if you have more luck!

---

<div class="post-metadata">

**Author:** ![Oolahk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Oolahk](https://forums.unrealengine.com/u/Oolahk)\
**Post date:** [October 15, 2018, 10:22pm UTC](https://forums.unrealengine.com/t/umg-remove-from-parent-still-valid/435585/4 "2018-10-15T22:22:21Z")

</div>

Thanks for your reply Sabre.

I checked out the post and found out that using “Collect Garbage” only works if you did not create a variable of the widget you add to the viewport. Upon further investigation, I figured out that my mentality is what’s incorrect. Instead of trying to remove it entirely, I just need to call it back later by adding to viewport again, vs trying to create it again. So for certain widgets that require variables, I check the validity and if it hasn’t already by created I create the widget, and if it is valid, then I would just add to viewport.  
This will not cause duplicates either. I will now have to go through and check to make sure certain widgets like hit points are properly removed from memory by not storing them as variables. Thanks!

---

<div class="post-metadata">

**Author:** ![Oolahk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Oolahk](https://forums.unrealengine.com/u/Oolahk)\
**Post date:** [October 15, 2018, 10:23pm UTC](https://forums.unrealengine.com/t/umg-remove-from-parent-still-valid/435585/5 "2018-10-15T22:23:18Z")

</div>

Thanks for your reply Sabre.

I checked out the post and found out that using “Collect Garbage” only works if you did not create a variable of the widget you add to the viewport. Upon further investigation, I figured out that my mentality is what’s incorrect. Instead of trying to remove it entirely, I just need to call it back later by adding to viewport again, vs trying to create it again. So for certain widgets that require variables, I check the validity and if it hasn’t already by created I create the widget, and if it is valid, then I would just add to viewport.  
This will not cause duplicates either. I will now have to go through and check to make sure certain widgets like hit points are properly removed from memory by not storing them as variables. Thanks!

---

<div class="post-metadata">

**Author:** ![mightyenigma](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mightyenigma](https://forums.unrealengine.com/u/mightyenigma)\
**Post date:** [October 31, 2018, 11:06pm UTC](https://forums.unrealengine.com/t/umg-remove-from-parent-still-valid/435585/6 "2018-10-31T23:06:42Z")

</div>

I got around this by set is enabled to false before remove from parent.  
And then checking whether the widget is enabled if it passes the isvalid check.

---

<div class="post-metadata">

**Author:** ![TRI99ER](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TRI99ER](https://forums.unrealengine.com/u/TRI99ER)\
**Post date:** [October 20, 2019, 2:49pm UTC](https://forums.unrealengine.com/t/umg-remove-from-parent-still-valid/435585/7 "2019-10-20T14:49:40Z")

</div>

And what to do, if you have one variable of parent class and you want to reference with it multiple different widgets of child class? They are just lost in memory and never deleted.  
Why is it intended to work that way? To waste memory?

---

<div class="post-metadata">

**Author:** ![TRI99ER](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TRI99ER](https://forums.unrealengine.com/u/TRI99ER)\
**Post date:** [October 20, 2019, 2:50pm UTC](https://forums.unrealengine.com/t/umg-remove-from-parent-still-valid/435585/8 "2019-10-20T14:50:25Z")

</div>

It doesn’t work in any case.

---

<div class="post-metadata">

**Author:** ![Segab](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Segab](https://forums.unrealengine.com/u/Segab)\
**Post date:** [December 22, 2020, 5:15am UTC](https://forums.unrealengine.com/t/umg-remove-from-parent-still-valid/435585/9 "2020-12-22T05:15:12Z")

</div>

This works, thank you!
