I try to spawn a user widget and destroy it after an animation has played. However i always get the following warning for all widgets created:
UWidget::RemoveFromParent() called on ‘/Engine/Transient.UnrealEdEngine_0:GameInfoInstance_C_0.DamageWidget_C_26’ which has no UMG parent (if it was added directly to a native Slate widget via TakeWidget() then it must be removed explicitly rather than via RemoveFromParent())
How do i destroy an added widget? I can simply hide it but iam afraid of memory issues …
You should be destroying the component, not the widget. Or are you reusing the component? Asking as I see you configure the component with nodes rather than:
Generally speaking, an orphaned dereferenced widget will get scooped by Garbage Collection. You can run Get All Widgets of Class to debug the number of widgets that are kept alive. If they do not go away because of the component dependency, you could try calling Collect Garbage manually.
The longer I look at this, the stranger it gets. Never seen an approach like this. You’re using the component to bring World Space widgets to life and then orphan them on purpose. Brilliant & mad at the same time!
When i try to destroy the added widget component ue4 deletes the wrong widget component if a second one is spawned before the first gets destroyed (so the first one never gets deleted). I tried working with an array and destroy the first entry but it doesnt change a thing
On BeginPlay this component will create a new widget from class, wait 2s and then destroy itself - it will also take down the created UMG widget with it ← that’s one of the advantages of WCs, they maintain the lifecycle of the widgets they own.
the UMG widget created by the component does just this:
Now, instead of Adding a generic Widget Component, you add your own, with its own logic:
And the whole thing will cease to exist within 2 seconds. There’s also a way to do it without using the Delay node. The UMG widget can inform the owning component that its animation has finished playing. This way you do not need to hard code values or even sample the animation length.
Anyway, note how no hard references are created this way. There’s little else to worry about.
hey man thanks for detailed suggestion. It tried your approach and it works like a charm!
However i still have one question left: I never call “destroy” or remove anywhere but the widget still gets destroyed after playing the animation (wich is desired i still want to know if i missed something).
Here are the blueprints for anyone having the same problem:
hey, i restarted the engine and the component did get destroyed like it should be sigh …
However now i bind the event to animation finished and destroy the component afterwards. Thank you so much for your solutions and patience. Have a nice weekend!
Just wanna say, this is a great method. I’ve been having a heck of a time destroying components in 5.1, but this is a great way that is working for me!