Add a element created a number of times, based on a variable

I want to add a element to the hud equal to a variable owned by the player character


A Visual Representation to grasp the goal. The Gold circles are the object that needs to repeat.

327673-visual-representation.png

It’s just a progress bar using an image :slight_smile:

Interesting, so if I’m falling this correctly you make a whole separate widget for the actual gold circle to be created in. but in the Status bar or hud widget, I only make a horizontal box. which calls upon it or spawns it in the boxes boundries.

Now I would think that as long as I make the horizontal box “size to contents” in it’s settings this would allow for 1-22 for example gold circles without issue?

If I am understanding correctly, this should be pretty simple to do.

  1. Create a widget such as a horizontal box in your parent HUD widget class and check “isVariable”

  2. Create a function in your widget called “SpawnChildWidgets” (or something more meaningful).

  3. Add the following code:

  1. Call the function where you need it. I.e. OnConstruct or somewhere else.

Make sure there is a value set in the Player Controller variable.

Hope this helps.

Alex

Unreal Engine is entirely based of the Object Orientated Programming paradigm.

Everything inside the widget graph is some form of a widget. Instead of creating separate widgets for your child objects, you could spawn an image widget and then manually set the brush (textures materials etc). But that is more work. It is easier to create a custom widget, add your image, set your properties, and then use it as a template. You can even expose variables on spawn to manipulate the behaviour of each child to automate any custom conditions.

Now I would think that as long as I
make the horizontal box “size to
contents” in it’s settings this would
allow for 1-22 for example gold
circles without issue?

There are many ways you can manage the alignment of your widgets. Size box + horizontal box, grid panels, separate canvas etc. It really depends on what you want to do.

I.e. if you want to spawn them in a line with a limit, then just use a horizontal box and add a condition to the logic “don’t spawn more than x”.

If you want to have rows with x widgets per row, then use a grid panel.
There are many tutorials on YouTube regarding layouts in widgets.

Also, you can pay attention to the clipping options, so you can ensure they don’t overrun the specified region.

Hope this helps.

Alex