I’m fairly new to UE4, having a pretty strong Unity background. Right now, what I’m trying to do is create a progress bar that displays the rewards at various levels. I’m using a pair of Horizontal Boxes in an Overlay, which is in an Overlay with the progress bar.
I also have a custom widget that populates the horizontal boxes with the following function:
void UTurretProgressBarWidget::InitializeProgressBar(APlayerController* OwningPlayer)
{
for (int i = 0; i < MaxLevel; i++)
{
UImage* Bar = WidgetTree->ConstructWidget<UImage>(UImage::StaticClass());
if (Bar)
{
UPanelSlot* slot = HorizontalPanelBack->AddChild(Bar);
UHorizontalBoxSlot* BarSlot = Cast<UHorizontalBoxSlot>(slot);
Bar->SetColorAndOpacity(FLinearColor(0, 0, 0,1));
Bar->Brush.ImageSize = FVector2D(4, 32);
BarSlot->SetHorizontalAlignment (EHorizontalAlignment::HAlign_Left);
BarSlot->SetVerticalAlignment(EVerticalAlignment::VAlign_Fill);
FSlateChildSize size = FSlateChildSize(ESlateSizeRule::Fill);
BarSlot->SetSize(size);
//BarSlot->Size.Value = 1.0f;
if (LevelStride > 0)
{
if ((i+1) % LevelStride == 0)
{
//UTurretLevelSymbolWidget* tempLevelWidget = WidgetTree->ConstructWidget<UTurretLevelSymbolWidget>(MaxLevelWidget->StaticClass());
UTurretLevelSymbolWidget* tempLevelWidget = CreateWidget<UTurretLevelSymbolWidget>(OwningPlayer);
if (tempLevelWidget)
{
tempLevelWidget->AddToViewport(1000);
tempLevelWidget->SetColorAndOpacity(FLinearColor(1, 1, 1, 1));
UPanelSlot* tempSlot = HorizontalPanelFront->AddChild(tempLevelWidget);
UHorizontalBoxSlot* levelslot = Cast<UHorizontalBoxSlot>(tempSlot);
levelslot->SetHorizontalAlignment(EHorizontalAlignment::HAlign_Fill);
levelslot->SetVerticalAlignment(EVerticalAlignment::VAlign_Fill);
levelslot->SetSize(size);
//UE_LOG(LogTemp, Warning, TEXT("CreatedWidget"));
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Unable to create widget!"));
}
}
else
{
USpacer* spacer = WidgetTree->ConstructWidget<USpacer>(USpacer::StaticClass());
if (spacer) {
//spacer->SetSize(FVector2D(1.f,1.f));
UPanelSlot* slot = HorizontalPanelFront->AddChild(spacer);
UHorizontalBoxSlot* SpacerSlot = Cast<UHorizontalBoxSlot>(slot);
FSlateChildSize size = FSlateChildSize(ESlateSizeRule::Fill);
SpacerSlot->SetSize(size);
SpacerSlot->Size.SizeRule = ESlateSizeRule::Fill;
//SpacerSlot->Size.Value = 1.0f;
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Error Spacer is null!"));
}
}
}
}
}
}
For whatever reason, the widget that I create via “CreateWidget” is invisible. What am I doing wrong here?
Edit: D’oh! I saw a typo where I was storing a UImage in a USpacer. The widgets are still invisible, though.