# What is the proper way to create and destroy UMG widgets?

**URL:** <https://forums.unrealengine.com/t/what-is-the-proper-way-to-create-and-destroy-umg-widgets/296665>\
**Category:** UI\
**Tags:** unreal-engine, Widget, question, UMG\
**Created:** [October 19, 2014, 11:20pm UTC](https://forums.unrealengine.com/t/what-is-the-proper-way-to-create-and-destroy-umg-widgets/296665 "2014-10-19T23:20:29Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [October 19, 2014, 11:20pm UTC](https://forums.unrealengine.com/t/what-is-the-proper-way-to-create-and-destroy-umg-widgets/296665/1 "2014-10-19T23:20:29Z")

</div>

Hello, to create UMG widgets i use Create Widget and then add to viewport, should i create it only once and then just toggle visibility or it’s fine creating the widget everytime? There is no Destroy Widget, so i assume Remove from Viewport destroys the widget or at least removes it’s reference for late destruction, but what about it’s children? Do i need to clear them before removing from the viewport, or he will do that automatically when he’s removed from the viewport? Thank you

---

<div class="post-metadata">

**Author:** ![BaronPumpky\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BaronPumpky\_1](https://forums.unrealengine.com/u/BaronPumpky_1)\
**Post date:** [December 5, 2014, 3:29pm UTC](https://forums.unrealengine.com/t/what-is-the-proper-way-to-create-and-destroy-umg-widgets/296665/2 "2014-12-05T15:29:02Z")

</div>

I’d love an answer to this. I would assume removing the widget would clean it up as well, but I don’t see anything about that online.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e729f54e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e729f54e](https://forums.unrealengine.com/u/anonymous_user_e729f54e)\
**Post date:** [December 23, 2014, 9:26pm UTC](https://forums.unrealengine.com/t/what-is-the-proper-way-to-create-and-destroy-umg-widgets/296665/3 "2014-12-23T21:26:32Z")

</div>

Hello xlar8or,

When a widget is removed from parent or removed from viewport it stays in memory. A new widget is not created beyond the initial creation, it is simply added to the viewport. There are a couple of important things to note.

1. The Event Construct will fire every time it is added to viewport.
2. A widget can be added to viewport more than once (in effect doubling it up, this can result in a widget that cannot be removed)
3. Though the widget is removed from viewport the variables within the widget retain what ever values that have.

I hope that this answers the questions that you had.

Make it a great day

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [December 23, 2014, 9:30pm UTC](https://forums.unrealengine.com/t/what-is-the-proper-way-to-create-and-destroy-umg-widgets/296665/4 "2014-12-23T21:30:04Z")

</div>

Thank you for taking the time to answer my question, so how do i actually remove it from memory? Should i just leave it to the GC after removing it from the viewport?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e729f54e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e729f54e](https://forums.unrealengine.com/u/anonymous_user_e729f54e)\
**Post date:** [December 23, 2014, 10:02pm UTC](https://forums.unrealengine.com/t/what-is-the-proper-way-to-create-and-destroy-umg-widgets/296665/5 "2014-12-23T22:02:58Z")

</div>

Hello xlar8or,

Yes, I believe it would be best to let the garbage collection handle it after it has been removed.

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [December 23, 2014, 10:04pm UTC](https://forums.unrealengine.com/t/what-is-the-proper-way-to-create-and-destroy-umg-widgets/296665/6 "2014-12-23T22:04:19Z")

</div>

Ok thank you 🙂

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_913c51ed](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_913c51ed](https://forums.unrealengine.com/u/anonymous_user_913c51ed)\
**Post date:** [July 8, 2016, 9:09am UTC](https://forums.unrealengine.com/t/what-is-the-proper-way-to-create-and-destroy-umg-widgets/296665/7 "2016-07-08T09:09:28Z")

</div>

Thanks for the reply

---

<div class="post-metadata">

**Author:** ![biubiuty3](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/biubiuty3/32/88719_2.png) [@biubiuty3](https://forums.unrealengine.com/u/biubiuty3)\
**Post date:** [October 1, 2016, 3:14am UTC](https://forums.unrealengine.com/t/what-is-the-proper-way-to-create-and-destroy-umg-widgets/296665/8 "2016-10-01T03:14:23Z")

</div>

great answer! 😃

---

<div class="post-metadata">

**Author:** ![Kokuyouseki](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kokuyouseki](https://forums.unrealengine.com/u/Kokuyouseki)\
**Post date:** [July 12, 2017, 11:02am UTC](https://forums.unrealengine.com/t/what-is-the-proper-way-to-create-and-destroy-umg-widgets/296665/9 "2017-07-12T11:02:01Z")

</div>

So far I found no way to remove widgets completely.  
GC appears to not do anything about them either as long as your level is running.  
This goes of course for dynamically created buttons etc. as well, so if you want to make an inventory that is not constant, every time you “remove” an item, it will stay with you forever.  
So all you can do is use the already created ones and only create new ones if you need one.

I really hope they add a delete widget node eventually. After all this time I doubt it though.

---

<div class="post-metadata">

**Author:** ![Two-faced](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Two-faced](https://forums.unrealengine.com/u/Two-faced)\
**Post date:** [February 5, 2019, 11:31am UTC](https://forums.unrealengine.com/t/what-is-the-proper-way-to-create-and-destroy-umg-widgets/296665/10 "2019-02-05T11:31:24Z")

</div>

Don’t forget to invalidate any timers going in the widget, otherwise GC won’t destroy it.

---

<div class="post-metadata">

**Author:** ![Ethan\_cc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ethan\_cc](https://forums.unrealengine.com/u/Ethan_cc)\
**Post date:** [February 20, 2025, 1:45am UTC](https://forums.unrealengine.com/t/what-is-the-proper-way-to-create-and-destroy-umg-widgets/296665/11 "2025-02-20T01:45:14Z")

</div>

Since my program is very complex, I don’t know which reference counter isn’t deleted. !so sad~
