UMG: Change widget index in a vertical/horizontal/scroll box?

I’m creating widgets through code and adding it to a Scroll box:

UScrollBox* box = Cast<UScrollBox>(GetWidgetFromName("BP_LogBox"));

URichTextBlock* text = WidgetTree->ConstructWidget<URichTextBlock>(URichTextBlock::StaticClass());

which works perfectly fine, however! I can’t seem to change it’s index within the box!
I need the new text boxes to appear at the top, but they are just going to the bottom of the box.

box->ShiftChild(0, text);

Doesn’t do anything at all, neither does box->InsertChildAt.

So, how can I get my widgets to be added (or moved) to the top of the scrollbox container?


Edit: Do slots have something to do with it? I can’t figure out how to use them.

Bear in mind that all of the functions that insert children at specific indices are marked as editor only (see PanelWidget.cpp) - I can’t remember the exact reason, but IIRC every existing widget in the box has to be rebuilt if you change the indices.

If you want to insert them at specific indices, you actually need to manually remove all the other children then re-insert in the correct order.

Hmm, seems like an oversight that there’s no way to Add children to the beginning by default (maybe a checkbox on the panel), considering that’s how most games would function with new items.

I tried storing all my items into an array, inserting new items to the beginning of the array and repopulating the panel each time, however that caused a ton of lag and crashed unreal once the list was long enough.

Oh, the joys of UMG.