Hi everyone.
I have been using code to create a Widget Component to show a Confirm or cancel option in the HUD, and I have set it to the correct Class and the Widget Space to “Screen” value, but I can’t seem to be able to display the HUD in the World even though when I check the Actor the Component it’s attached correctly and it’s using the corresponding Class, I will post the code down bellow and I hope that someone here can help me out with this issue.
void ABuilding::SetupBuildingWidget()
{
UWidgetComponent* Widget = NewObject<UWidgetComponent>(this, UWidgetComponent::StaticClass(), TEXT("Building Widget"));
if (!Widget)
{
return;
}
FStringClassReference BuildConfirmReference(TEXT("/Game/UI/BuildBuildingHUD.BuildBuildingHUD_C"));
if (UClass* ConfirmClass = BuildConfirmReference.TryLoadClass<UUserWidget>())
{
UUserWidget* ConfirmBuildWidget = CreateWidget<UUserWidget>(GetWorld(), ConfirmClass);
Widget->RegisterComponent();
Widget->SetWidgetSpace(EWidgetSpace::Screen);
Widget->SetWidgetClass(ConfirmBuildWidget->GetClass());
Widget->bHiddenInGame = false;
Widget->SetTwoSided(true);
Widget->bVisible = true;
Widget->AttachToComponent(RootComponent, FAttachmentTransformRules::SnapToTargetIncludingScale);
}
else
{
Widget->DestroyComponent();
}
}
and here is a Screenshot of the Widget has it should appear and how its appearing right now.
Any help with this would be greatly appreciated and another thing is that If I edit any value from the widget from within the PIE, it automatically renders the Widget correctly in the screen. Thank you.