Removing widget creates "Spectre" widget problem

Hello, I have a problem regarding User Widget that I cannot comprehend at all what’s going on.

I have widget class named “Dice” that is spawned upon Wrap Box.

I’ve made myself a debug button with “Clear children” node to remove all of those Dices and it works properly there and triggers Event Destruct node in them.

However, due to one planned functionality of the dice, when one custom event is called inside it, if requirements are met, it is supposed to destroy itself manually. For that, I added “Remove from Parent” with Target “self” in that function.

Now the strange thing is, even though it has nothing else that is supposed to have reference of it, which from I read should cause this object to be grabbed by garbage collector and removed, it stays in the Wrap Box it was spawned in.

For a moment, I thought it just didn’t removed the child from Wrap Box properly but when I added “Has any children” for debug, engine returns “false” for this Wrap Box that “spectre” Dice is in.

When checked with Widget Reflector, you can see that Dice widget in the Wrap Box though, giving clue that it is indeed has children to contrary what “Has any children” node returns.


When trying to use my debug button to remove all children from all Wrap Boxes, it doesn’t affect that “spectre” Dice widget.

Now even weirder thing with this “spectre” Dice widget is the fact that you can interact with it and use Drag&Drop function and move it to another Wrap Box as you normally could with any other Dice widget. After that, the widget suddenly acts like a normal Dice widget but leaves behind a copy in the original spot that suddenly can’t be interacted it again.

When checked with Widget Reflector both Dice widgets (the one moved to another Wrap Box and in the original Wrap Box) do exist both at the same time and even share the same address in memory.

In this case, when using debug button to remove all children from Wrap Boxes, it removes the Dice widget moved to another Wrap Box but still doesn’t affect the “spectre” Dice widget in original Wrap Box. For some reason, doing that allows to interact with that original “spectre” Dice widget again!


I tried removal methods including “Remove from Parent -self” node, on creating Widget adding object reference to that Wrap Box and index to the Dice widget during construction and then using those variables for “Remove child At” but the result is the same and my confusion is insufferable as I dont know why this happens at all.


If this issue won’t be resolved this creates kind of a big problem as functionality to remove that Dice widget is important to game rules and simply using a workaround and hiding the widget and moving it to separate container means that memory will still be used for something that does not need to exist and that is just a bandaid solution.


Any ideas how to fix that issue or better, how to remove properly a widget that is a child by its own instead of trying to remove it by parent?

I’ve made a video on YouTube so you can see in practice how this looks like: YouTube Video

Hey there @Vulpixon732! Welcome back to the forums! This is definitely a bit of a headscratcher. For literally everything else I’d just say “Ahh force destroy it and move on” but since UMG forces you to just remove it from it’s parent so it can garbage collect it on it’s own, this is a bit of a problem. Here’s a question that might guide us a bit, so the dice holder doesn’t recognize it has children, but what does the dice think it’s parent is? This might be occurring because the unparenting is happening in the same frame it’s being added, though I’m entirely uncertain on why.

3 Likes

How exactly can I check that when the game is on?
If by Widget Reflector, it does show as that Wrap Box is indeed a parent even though “Has any children” function says otherwise.

As to why it should destroy itself on creation, the case is that it “technically” shouldn’t when spawned during gameplay but later when conditions are met, just didn’t implemented debug buttons to create the conditions for the Dice widget to initiate destruct on itself.

For debugging reasons I just made it spawn with conditions that should cause it to destroy itself, just to check if the removal function actually works for the future, when it will actually destroy after being spawned. The reason the check is on Construct is because the same function call updates the Health Status for separate widget containing information about that Dice, which then checkes if the dice is supposed to be destroyed and should remove it in that case.

Should I try to remove that function on construction and call it after to see if the issue was as you stated, happening in the same frame it’s being added?

UPDATE: I tried doing the above and yes, the issue was the fact that it was doing the remove on the same frame it was causing the problem. After I detached the function and launched it after the spawn, it despawned and triggered destruct properly. Which means this issue will never happen during normal gameplay as it will never spawn a fully broken dice.

Thank you for the lead and help!

1 Like