Hey all,
I’m having an issue where widgets created in C++ on runtime do not show up on my Canvas.
The C++ Code:
UUserWidget* SlotWidgetItr = CreateWidget<UUserWidget>(GetWorld(), DefaultSlotWidgetClass);
if (SlotWidgetItr)
{
//Add to slot widgets reference array
SlotWidgets.Add(SlotWidgetItr);
UCanvasPanelSlot* WidgetOnCanvas = MenuCanvas->AddChildToCanvas(SlotWidgetItr);
if (WidgetOnCanvas)
{
//Set Anchor and alignment to centre
WidgetOnCanvas->SetAnchors(FAnchors(5.f));
WidgetOnCanvas->SetAlignment(FVector2D(5.f));
//Set position
FVector2D SlotPosition = GetSlotPosition(i, MenuPayload.Num());
WidgetOnCanvas->SetPosition(SlotPosition);
UE_LOG(LogTemp, Error, TEXT("Slot %d: %f %f"), i, SlotPosition.X, SlotPosition.Y);
//Set size to passed size of widget
WidgetOnCanvas->SetSize(SlotSize);
}
}
I’ve run the same code in BP and it works, just not sure if its translating right in C++.
The Widget is a Canvas Panel that’s added to viewport through the Player Controller Class. It runs the above C++ function on its Blueprint Construct.
I’d appreciate it if anyone could tell me what I’m missing.
Thank you!