Unresolved external symbol when trying to add widget to the viewport

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();     }    } 

1 Like

Hello,
Depending on what you use, you need to add “UMG”, “Slate”, “SlateCore” to your public dependencies in your ProjectName.Build.cs



PublicDependencyModuleNames.AddRange(new string] { "Core", "CoreUObject", "Engine", "InputCore", "UMG" });


8 Likes

Thanks!

1 Like