This does not 100% work for me. The widget gets constructed, but as soon as I extend it in BP and add children, they get bugged out.
Here is an example:
TSharedRef<SWidget> UMessageBoxWidget::RebuildWidget()
{
auto rootWidget = Cast<UPanelWidget>(WidgetTree->RootWidget);
if (!rootWidget)
{
rootWidget = WidgetTree->ConstructWidget<UCanvasPanel>(UCanvasPanel::StaticClass(), TEXT("RootWidget"));
auto slot = Cast<UCanvasPanelSlot>(rootWidget->Slot);
if (slot)
{
slot->SetAnchors(FAnchors(0, 0, 1, 1));
slot->SetOffsets(FMargin(0, 0, 0, 0));
}
WidgetTree->RootWidget = rootWidget;
}
auto widget = Super::RebuildWidget();
if (rootWidget && WidgetTree)
{
auto image = WidgetTree->ConstructWidget<UImage>(UImage::StaticClass(), TEXT("Background"));
rootWidget->AddChild(image);
auto slot = Cast<UCanvasPanelSlot>(image->Slot);
if (slot)
{
slot->SetAnchors(FAnchors(0, 0, 1, 1));
slot->SetOffsets(FMargin(0, 0, 0, 0));
}
}
return widget;
}
I create CanvasPanel as root and add background image. It looks ok at first glance in UMG editor, but the moment I drag in text, this happens:
Also I can no longer delete the TextBlock or do anything with it. I have also tried it with UBorder instead of an image. Am completely stumped… any help would be appreciated.