Widget component doesn't get destroyed with parent actor?

Spawn actor w/ widget component.
Destroy actor.
Widget tick ends.
Widget still prints key events, variables still accessible, and prints reference to self. Shouldn’t it no longer exist?

And, every time actor is spawned, an additional widget now prints. Press a key and get something akin to:
W_Widget_0
W_Widget_1
W_Widget_2
W_Widget_3 and so on…

I’ve tried directly destroying the component or removing component’s widget but it seems indestructible.

Possibly related to:

UPDATE:
I found the widget(s) are no longer accessible (e.g. GetAllWidgetsOfClass) after about 30-50 seconds, and if there are multiple they all disappear at the same time as if part of a garbage flush.

The above mentioned “prints key events” is where I’ve added EnhancedInput events to the widget which may be a bit odd. I was surprised they could be added. But, they continue working after the widget is supposedly destroyed, and stop when finally “flushed”.

I find it odd behavior but seems at least there won’t be a buildup of 100 widgets in memory by the end of a match which was the big concern.

Widgets follows Unreal’s garbage collection cycle. When widget get removed from viewport it doesn’t get release right away and have to wait till next GC. Meanwhile tick, input, delegate would still run on the widget.

If my widgets have ticks/accept key inputs, I usually do some bool or IsInViewport to check if the widget should run the function.

As to the possible 100 widgets in memory build up that’s up to how you setup these widget. Some widgets are suppose to build up and let GC handle them like damage number.

Or if you have enemy HP widget then it’s better for enemy actors to set their own HP widget, instead of widget having a reference to enemy and trying to get HP from widget tick.

2 Likes

Thanks for explaining! It makes sense with what I’m seeing now.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.