I had a problem where I was trying to add widgets to a vertical box in a loop using C++, and this post has a ton of views, so I’ll post what my fix was, in case it helps someone else.
Here I have a UI that displays character text on the HUD. The TextBlock holder class is in a BarkLineClass, like this:
const int LineCount = BarkContainer->GetChildrenCount();
FName LineName(FString::Printf(TEXT("BarkLine_%d"), LineCount));
UUserWidget *Widget = CreateWidget(PlayerController, BarkLineClass, LineName);
if (UBarkLine *BarkLine = Cast<UBarkLine>(Widget))
{
BarkLine->Text->SetText(NewText);
// If the name of the widget is the same as another it will corrupt
BarkContainer->AddChildToVerticalBox(Widget);
}
Was about ready to climb the walls and then after some UE_LOG’s showed corruption in the widget tree, I tried creating those sequential names and it worked. Fixed!