Widgets are invisible in the player's viewport

Any widgets I add to the player’s viewport are invisible. Not invisible as a widget visibility state, if I try to change their visibility state to visible they still don’t appear on the player’s screen. I’m with this issue over a week now and I can’t find anywhere an answer for that.

EDIT

GameHUD.h

void AGameHUD::CreateInvWidget()
{
	//This function creates invWidget and is called on AGameHUD's begin play function

	if (invWidgetTemplate)
	{
		invWidget = CreateWidget<UMainInvWidget>(GetWorld(), invWidgetTemplate.GetDefaultObject()->StaticClass());
		if (invWidget) {
			invWidget->AddToViewport(0);
			invWidget->SetVisibility(ESlateVisibility::Visible);
			if (invWidget->GetVisibility() == ESlateVisibility::Visible)
			{
                            //I get this message when playing the game
				GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Red, "invwidget visible");
			}
		}
		else
			GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Red, "invWidget is null! @GameHUD::BeginPlay");
	}
	else {
		GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Red, "invWidgetTemplate is null! @GameHUD::BeginPlay");
	}
}

ShooterGameHUD blueprint that inherits from GameHUD.h

(added this Add To Viewport node on the Event Toggle Show Hide Inv Widget only for debugging purposes)

Construct event from the main inventory widget, which inherits from UMainInvWidget (an empty class that’s only used so I can reference this widget in c++) .

(sorry for my bad english)

Thanks in advance!

Added some screenshots and some of my code. Btw thanks for the reply! :slight_smile:

It works! Thank you SO MUCH! I’ve been having this issue for over two weeks now.

It would be helpfull if you posted some screenshot of the Blueprints where you create the widgets and add them to the player viewport.

Ok you use StaticClass() to get the class you want to create. This doesn’t work, because StaticClass gets resolved at compile time. However, the C++ doesn’t know about blueprints at compiletime. You want to use ->GetClass() to resolve this at runtime.

Edit:
You also should not need the GetDefaultObject()