I want to add widget to the viewport using c++, but I’m getting error:
Act_31.cpp.obj : error LNK2019: unresolved external symbol “__declspec(dllimport) private: static class UClass * __cdecl UUserWidget::GetPrivateStaticClass(void)” (_imp?GetPrivateStaticClass@UUserWidget@@CAPEAVUClass@@XZ) referenced in function “private: void __cdecl AAct_31::GameCicle(void)” (?GameCicle@AAct_31@@AEAAXXZ)
What I am doing wrong?
.h
class UUserWidget;
UCLASS()
class HOME_API AAct_31 : public AActor
{
GENERATED_BODY()
UFUNCTION() void GameCicle();
public:
AAct_31();
class UUserWidget* blackLinesWidget;
class UClass* blackLinesWidgetClass;
virtual void Tick(float DeltaTime) override;
protected:
virtual void BeginPlay() override;
};
.cpp
void AAct_31::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
GameCicle();
}
void AAct_31::GameCicle()
{
FStringClassReference blackLinesWidgeClasstRef(TEXT("/Game/Blueprints/UI/blackLines"));
blackLinesWidgetClass = blackLinesWidgeClasstRef.TryLoadClass<UUserWidget>(); // Error
if (blackLinesWidgetClass)
{
blackLinesWidget = CreateWidget<UUserWidget>(this->GetGameInstance(), blackLinesWidgetClass);
if (blackLinesWidget)
blackLinesWidget->AddToViewport();
}
}