i have:
A blueprint Widget with health display;
A Hud derived class.
i’m trying to “attach” this widget to this hud class following this tutorial
there are two problems:
1.
.h
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Widgets")
TSubclassOf<class UUserWidget> GameHUD;
UUserWidget* m_gameHud;
.cpp
if (GameHUD)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("it works"));
m_gameHud = CreateWidget<UUserWidget>(GetWorld()->GetGameInstance(), GameHUD);
if (m_gameHud)
{
m_gameHud->AddToViewport();
}
}
the if(GameHUD) is returning false, to create a widget you have to pass a pointer to widget class(?) and apparently it’s not working like in the tutorial, plus, if i take this if out, the editor crashes e doesn’t even open afterwards.
2.in the tutorial the widget is attached to a player controller, so i don’t know if i’m supposed to hud class control widgets.