Help with dealing with multiple widgets reducing performance.

To display damage numbers I’m creating a widget and adding to viewport. The widget is removed after 1 second, which is enough time for the player to see the damage number. However, I have a rifle and its shoots very fast, which means after a while it will be lots of widgets added to viewport. For example, If I fire 100 times in 10 seconds, this will make 100 widgets where they are only being removed after 1 second. So, in 10 seconds I will have 100 widgets created and only 10 removed. Eventually this will impact performance and the FPS will be largely reduced to the point that is unplayable. Any tips on how to solve this?


inside the widget
How I use to display the damage

#1 Pooling - create a handful of widgets upfront and recycle them. Rather than the constant expensive creation and then reliance on Garbage Collection, construct them once and keep them at a ready - display when necessary. Only create more if more are actually needed. Every now and then trim the array to keep the memory footprint at bay. You’d need to write the system from scratch; there may be something on the marketplace.

#2 Use a single widget with one canvas that has many text widgets. Have a single widget with a canvas that dynamically adds native text (ideally, combine it with pooling) and animate that - instead of Tick shifting user widgets in the viewport, have animation shift native text blocks in canvas:

#3 Simplify the hierarchy of the widgets as much as possible, run text in Simple Mode. User WidgetTex Block. No innate canvas, borders, no fluff.

#4 Read through some of the tips here, see what you can find. Not all will be applicable but, in short: avoid Tick and property / function binding.

#5 Animations trigger events, use Finished rather than run another node Delay for every widget. Not quite sure if beneficial, though:

image

#6 Don’t use UMG at all. :exploding_head: Have a look at the now venerable HUD Class - it may seem crude and featureless but it can render UI elements fast:

image


All of the above will be much harder than what you’re doing atm, of course. You’d need to have arrays and track data yourself.

2 Likes

Do you think that HUD class will affect performance if I spawn several of it?

No, HUD is a singleton (kind of) framework class:

Like the Game Mode, or the Player Controller. There is no one-click solution to what you’re attempting.

I found this: Is there a way to optimize widget components for floating damage numbers? - #18 by Krileon
Maybe this will work. I will see if I can do it.
edit: it’s using UE5 :c


I was following the tutorial https://www.youtube.com/watch?v=MrLC0kou9k8 and at 2:58 the “User Parameters” has an add + sign next to it, but in UE4 it does not. What could it be?
Tutorial:
ue4

1 Like

Perhaps I am late to the party, and also maybe that’s not exactly what you want to do, but I think it’s worth considering: why not have a single widget for every enemy, and the value there would update every time they take damage?