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.
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.
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:
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.
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.
So you have two options it seems (unless there’s some hidden swap function I don’t see):
Inherit from panel in C++ and write your own swap function either directly manipulating Slots which is protected, or by exposing ReplaceChildAt and implementing swap in BP.
Or you can write a BPLibrary in C++ and do the same. Either exposing ReplaceChildAt by writing a function that takes the parent, or writing a swap function taking the parent and the widgets or their indices to swap.
For folks without a lot of inherent C++ know-how, I’d recommend the second as it keeps all Panel widgets available (vertical box, panel, etc), and there’s lots of examples of simple BP libraries online.