Correctly handling widget creation and removal

  1. I am not sure if garbage collection actually gets rid of the widgets at some point

Yes, providing nothing else references the widget.

When the player mounts the horse again, I must remove the marker, of course, since it’s no longer valid. I do this by using the “Remove From Parent” function.

Sounds fine. But how do you know which widget to remove? How do you reference it in the first place after Creating and Adding it to canvas.


There’s no need to Get All Widgets Of Class here.

I believe OP is using it for debugging - to observe how widgets are leaking memory.

If they’re using it to actually find widget(s), then yeah this can lead to things not going all too well.


@Shizai why create / remove the widget? Why not create 1 and then show / hide it only. Much cheaper and no shenanigans with the GC? Which could look like so:

You can, of course, use canvas instead of viewport. Same principle.