UMG set child index

Hi all,
I’m trying to create a bar that can be dinamically filled/emptied by using two +/- buttons. It works by using several instances of two simple widgets that contain the images for empty or full. The bar in question:


The problem is that everytime I change the value of the bar I have to go through all children to find the first empty child (or full, depending if I’m adding/subtracting). Then when I have the index of the child I have to switch from empty to full, or vice versa, I have to remove all children from that point to the end (GetChildrenCount), and then add the child with the new value, and then finally recreate the rest of the bar with new empty widgets.

Now, this works fine, but by using it ingame a few times, a lot of empty/full widgets are created and abandoned very quickly. This is because UMG widgets can’t actually be destroyed at runtime but just sit there, waiting to be collected by the gc. I find this is not a healthy solution, and would love to be able to just “switch” a widget’s class at runtime or more realistically to be able to dynamically add a new child at a given index with the existing children’s indexes updating automatically.

PS: I find it strange that basically no one, a part from one single guy in AnswerHub (that received no answers from January), has pointed this out already, so I figure there probably is a more intelligent way of doing simple bars like this I’m trying to do, and that my stupid brain just hasn’t thought of it… so if there’s a better way could any one please illuminate me?

Thanks in advance, and sorry for all these many words but I’m very tired, and I’m not being able to synthesize concepts correctly :slight_smile:

Have you considered using a masked progress bar?

The way I have gone about something similar by simply hiding or “Collapsing” widgets or specific widget layers (Widget “State” as you called it).

This way they will only have the “check/set visibility” overhead, and each of the widgets would already be created and would not need to be removed and re-added to the screen.

This may not be the most efficient way of doing it, but I think its a step in the right direction for what you are looking for.

I suggest using simply an image with a scalarParameter. I’m pretty sure that the mask can be generated within the material editor since it’s seems like a simple x and y coordinates function.

I’ve created two 32x32 images, an empty and a filled block:

7dad4204f17006b15f145556f37801a0bf5181a0.png 5c8fe3baa4fc57b130787cbd756c2c9606f637af.png

Tiled them horizontally in a progress bar:


And change the value by:


Hi Everynone,
your solution seems good.
My bars are dynamic, so I just put on construct a multiply for this integer (that decides at runtime the bar length) * the width of my bar units (50) and set the override width accordingly for size box containing the scroll bar. The buttons +/- are now configured to make a 0-1 normalization (the parent is the size box with heigth/Y equal to my bar units, 50):


It works but for a single problem.
Apparently, there’s a signed zero value that I’m not being able to catch in any way when negative, probably because it isn’t exactly -0.0, but it’s neither equal to zero, so sometimes I can’t subtract the last value of the bar because instead of a real negative value I get this -0.0:

screenshot of the problem:

You try this ham-fisted approach.

Wow, didn’t knew about that node.
You are the man. Thank you Everynone.

Like this works with all scenarios: