[BUG] I need to remove the widget twice in order to remove it.


So, I have a widget that is a child of another widget and in order to remove it i need to execute “Remove from parent” twice. I have the latest unreal engine version installed. The widget was not created twice (Tested with print strings). Is just a single widget.

Have you tried get parent> remove from parent. You can also call remove all widgets

As a rule of thumb:

  • Try to avoid Remove from Parent, use Set Visibility whenever possible.

  • Definitely, never ever call Collect Garbage manually. Even when you think it is the right thing to do, it never is.

P.S. If Set Visibility needs to be called twice then you have created two widgets at some point.

1 Like

no, it hasnt been called twice because with print strings the last index of all widgets of that class return 0. Also, why i cant use Remove from Parent and Collect Garbage? RAM consumption reduces with that

What do we need to do to reproduce :backhand_index_pointing_up: this part not working? Are you saying you can observe a difference between the above and:


:man_shrugging:

It’s a costly operation the engine will perform automatically (after some time) - there’s no reason to call it in 99.99% of cases.

When I reproduce the top blueprint, the Widget doesn’t remove

When I reproduce the bottom blueprint, the Widget does remove

This is when the widget gets created:

Doing this on Character’s event tick returns 0 when the Widget gets created and the same when it gets removed once:

1 Like

Could you run a test:

  • remove the widget from parent once, do not Collect Garbage
  • keep ticking Get All Widgets
  • get a cookie, wait 70 seconds

What do you get?


Almost certainly irrelevant, but perhaps you could shed some light on this part:

Did you mean to set anchors of the canvas slot instead? As in:

This widget is not in the viewport anyway.


When I reproduce

What I meant was how do we reproduce it. Because, as you probably know, under regular circumstances, removing a widget from its parent works pretty consistently. What is irregular here, what’s special about this setup?


Also, most importantly:

the Widget doesn’t remove

Do you mean it does not get released from memory or it does not disappear from the screen? If it’s about memory release - automatic Garbage Collection is scheduled to happen much later, you just need to wait. It’s designed not to stress the system with frequent updates - calling it manually produces the opposite effect as @dZh0 mentioned.

Still the same

Oh thanks :slight_smile:

Base Widget:


Program Widget:


Window Widget:

Base Widget Contains a Retainer Box whose child is the Canvas Panel

It doesn’t disappear from the screen.

Update:

idk what I changed, everything is the same. But now, the widget disappears when I remove it but the Print Strings still returns 0. To fix this I added the Collect Garbage node and now it works.

Idk why this suddenly got fixed because I didn’t change nothing so I guess it was a bug?