I’m working on a circular menu that will need to draw itself every time it opens. When the game wants to draw it, I have it configured to take the array of arguments (inventory items, conversation responses, or whatever), and for each argument a) create one of my icon userwidgets and b) populate that icon with the desired label/graphics. The issue is, when the menu closes I don’t want to retain every icon widget in memory, especially as I’ll likely need a different number of them the next time that menu opens. However, I don’t see a Destroy node I can use on a widget- is there a specific way we’re supposed to destroy UMG objects once we’re done with them?
Use the “remove from Parent” Node.
Hmm okay, will that cause it to get swept up in the next GC pass?
in most cases there are at least two objects which holding your widget as a reference.
The first one is the viewport, the reference is created when call “Add to Viewport” so calling remove from Parent will delete that reference again.
The second one is the object which holds the reference after you called “Create Widget” somewhere and saved the output inside an objectpointer.
If you want to remove that widget you can set your objectpointer to null AFTER you removed it from viewport by simply call the “set” node from your variable and set it to nothing, just leave it like this.
I think then you can be sure that UE will clean up this object.
One more Note: If you create a widget inside a nonpersistent class like a character,controller,hud (those will be reset on level load) you HAVE TO remove it from viewport before loading a level else
you may be ending up seeing your widget inside the new level and you are not able to remove it.
That’s super-helpful, thank you!
Thanks, this has helped with the is not rooted crash
I was told by a staff member that widgets that are created remain in memory forever, though I can’t find where I was told that right now.