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
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.
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.
- The Event Construct will fire every time it is added to viewport.
- 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)
- 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
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?
Hello xlar8or,
Yes, I believe it would be best to let the garbage collection handle it after it has been removed.
Ok thank you
Thanks for the reply
great answer!
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.
Don’t forget to invalidate any timers going in the widget, otherwise GC won’t destroy it.