Dirty old UMG widget instances are returned by CreateWidget()

With UE4.26,a call to CreateWidget() can return an old “dismissed” instance of a UMG widget if the same name is used. The returned instance retains the old state of when it was supposedly “dismissed”. This was not happening in the previous versions of UE4, where a newly fresh instance was returned.

Steps to reproduce:

  1. Add a Master widget on screen using CreateWidget() and explicitly setting the WidgetName parameter. Ensure this Master widget is containing some components that can retain state (e.g. a UEditableTextBox);
  2. Remove the Master widget (e.g. calling RemoveAllWidgets())
  3. (the Master widget instance should now not have any reference to it, so it should not be a not reachable object and be garbage collected when possible)
  4. Using a button/timer, re-create the Master widget as done in step 1 (i.e. calling CreateWidget() and explicitly setting the WidgetName parameter to the same previous value)
  5. In UE4.26, the “disposed” instance is returned retaining its old state. Instead, a new fresh instance is expected (and this was what happened in UE4.25 and before).

A workaround (that demonstrates also point 3), is forcing the garbage collection calling GEngine->PerformGarbageCollectionAndCleanupActors() between step 2 and step 4.

In the attached test project, you can verify the bug inserting some text in the editable text box widget. Pressing the first button, you can see the bug; pressing the second button you can see the workaround.

In the project, step 4 is implemented using a timer from the Game Mode, to be sure that no references to the old widget instance were retained somewhere.
In addition, the console command “obj refs name=[widgetname] shortly” is executed before and after all the relevant command. In the output log, it confirms (between step 2 and step 4) that the “disposed” widget instance is not reachable and is waiting to be garbage collected, writing the message “HUD_C /Engine/Transient.UnrealEdEngine_0:GameInstance_0.MyHUD is not currently reachable.

UMGRecycleBug.zip - Sample project

Hello,

We’ve made a switch to a new bug reporting method using a more structured form. Please visit the link below for more details and report the issue using the new Bug Submission Form. Feel free to continue to use this thread for community discussion around the issue.

Thanks

Hi , thanks. I already submitted it also on UDN.