Adding and removing widget to viewport ends in a crash?

Hello, I’m trying to add and remove a widget to the viewport, which works but crashes as soon as I close the PIE window. This is most often done by pressing the button once or twice, but definitely by spamming the button.

Does this be a Bug or how this could be explained and resolved/changed ?

1 Like

IIRC, when you RemoveFromParent(), it marks the widget as one to be destroyed and garbage collected. If you want to reuse the same widget, don’t RemoveFromParent(), just SetVisibility(Collapsed), and then SetVisibility(Visible) again. Or if you want to RemoveFromParent(), you should create a new widget each time you want to AddToViewport().

2 Likes

Unfortunately, creating a new widget after removing it also leads to the same crash. The aim is to spam numbers (damage points) on the screen which are then removed after an animation.

Also tried this version

Just a SINGLE add & remove does crash the editor !?

1 Like

The issue has been solved by disconnecting the Any Key Event from the Widget Interaction Component which did propagate the key through the function Press and Release Key. It seems that the component is trying to send the “1” key to the Widget which did be removed by the same key press.

My conclusion: Looks like a race condition issue of async tasks. Not a bug !?

1 Like

I’ve learnt through experience that it’s better not to override key events in widgets. It can engender various unexpected bugs, and in best cases it simply won’t work.
If you want to use input in widgets, better call ListenForInputAction node OnConstruction.

1 Like

In my case i have to use Widget Interaction Component, since i have to interact with an actor holding a cylinder arc displayed widget. There is no other (known) way to interact with this kind of actors otherwise.

@Tuerer Thank you for your time and effort, really appreciate it !

1 Like

Hi, can you post the code (and animation settings) that worked? Id like to do this too. Ty.

And did you take that guys advice to SetVisibility(Collapsed) - then reuse them by setting visible? Idk how many destroyed widgets it takes to lag, but your repeat use should answer that. Ty

1 Like

@XxNotAGamerxX As far as i experienced, i do reuse the reference stored in a variable and add these to the viewport to toogle visibility. I made an actor with a queue to add the damage number to be shown in the screen. These queue is limited on item count so that i can controll even on 1000+ hits how many damage numbers (widgets) are displayed on screen. The controll also drops numbers which are too old in time to catch up with the more accurate ones. Thi requires also a clear queue implementation if the actor is not getting any more hit/damaged.

I can post my (WIP) implementation shortly.

2 Likes

Thank you. It sounds like you know what you’re doing, and recreated the industry standard. I don’t know how to do this, so thank you for taking the time when you post it.

1 Like

@XxNotAGamerxX As promised here the WIP implementation of the damage number displayed above an actor on screen.





1 Like