Here is how I add new GridPanel to my custom UUserWidget class.
bool UInventoryWidget::Initialize()
{
Super::Initialize();
UCanvasPanel* RootWidget = Cast<UCanvasPanel>(GetRootWidget());
if (WidgetTree && RootWidget)
{
if (GridPanel == nullptr)
{
GridPanel = WidgetTree->ConstructWidget<UGridPanel>(UGridPanel::StaticClass(), TEXT("GridPanel"));
UCanvasPanelSlot* GridPanelSlot = RootWidget->AddChildToCanvas(GridPanel);
GridPanelSlot->SetAnchors(FAnchors(0.f, 0.f, 1.f, 1.f));
}
}
return true;
}
When I open Blueprint associated with my custom UUserWidget class I see in editor that grid panel was rendered but I don’t see in in Hierarchy widow. How to fix this?