How to reorder a widget's children during runtime in Blueprint?

307990-2020-07-24-23-20-31.png

To put it simply, for example I want that third scale box to move to the first slot of the horizontal box during runtime.
Some BP function like “Widget - change children slot to”.

I’ve read some other questions where it was recommended:

1. Clear the widget’s children, and add children again in the order I want.

  • I’ve had a partial success with this, as I was able to clear and add the children in the order I wanted.
  • However, that eliminated all other settings–like size (auto/fill), alignment, stretch, stretch direction, of the newly added children.
  • Maybe I’m being lazy here, but if clearing children and adding them again to reorder them means I also have to re-designate all settings of the newly added children, I feel like that would be too much of my time. There must be a better way.

2. Use "ReplaceChildAt’, “InsertChildAt”, “ShiftChild”, which are C++ functions not exposed to BP.

  • Erm… I can’t code in C++.

So this is where my luck ended, I’m looking for a better way to shift the order of a widget’s children during runtime using Blueprint. It makes me think there must be a way, because reordering children of a widget in UMG editor is as simple as drag and dropping it at the location I want. Or maybe there is a way to keep all the settings like size, alignment, stretch and etc when removing children and re-adding them. But so far, it seems like these settings where removed when I cleared them from widget’s children list.

[…]there must be a way

Sadly, you’ve explored the options available to blueprints. There is no painless way of doing it, unfortunately. It’s one of the more prominent shortcomings of the UMG. It’s a weird omission, indeed.


Another, somewhat hacky, way would be to keep those Scale Boxes in a canvas rather than a horizontal box. Canvas’ slot would then allow you to shift the position of each Scale Box freely, and without ruining the slot’s settings. But then you’re, kind of, rewriting what a horizontal box does…

I do understand why this might be a complete no-no in many cases.


adding them again to reorder them
means I also have to re-designate all
settings of the newly added children

If you wrapped the scale box in a custom widget, it could keep track of its own slot settings in a struct. Once readded to the panel, a wrapped child can apply the stored settings to its own horizontal box slot.

Got it, thanks, I ended up using another workaround. Thanks! :slight_smile:

"2. Use “ReplaceChildAt’,
“InsertChildAt”, “ShiftChild”, which
are C++ functions not exposed to BP.”

Same problem here. Would be really needed to have these functions exposed to Blueprints.

lol, dodgyhodgy, you said you “Ended up using another workaround”. What workaround did you use? Thank you.

lol, you said you “ended up using another workaround”. What workaround did you use? Thank you.

What workaround did you use?

The best option is to expose the things you need to c++, but if you don’t want it because its supose to be a simple project like mine you can use this workarround, I made it to add childs in between, but use the same logic to reorganize, you just need to adapt to your own needs:

334672-ans2.png

334673-ans3.png

I just collected array of children references, sorted it as I needed and then iterated through it with foreach in blueprint and did ParentWidget->AddChild, after that they became reordered.

It was 5.0.3, however

2 Likes

Also had the same question, and failing to find any documentation or examples on DynamicEntryBox, I’m now attempting to just re-order grid slots which hopefully will be fine for my limited needs:

Hey guys! Trying to contribute here with the solution I found for blueprint widget ordering. I’m almost sure it’s the same as the @JediKnightChan found! I was trying to find a better way, but didn’t find.


In this case I needed reordering because I wanted to have that little “pull to place” while I’m dragging a widget.
GIF Recording 2024-02-16 at 5.42.43

Hey Raktou do you have a broader explanation of this? Just using your screenshot alone it doesnt work