LNK2019 ERROR

MyHUD.cpp.obj : error LNK2019: ??뫪? ?? ??ࠧ??襭??? ???譨? ᨬ??? “__declspec(dllimport) private: static class UClass * __cdecl UUserWidget::GetPrivateStaticClass(void)” (_imp?GetPrivateStaticClass@UUserWidget@@CAPEAVUClass@@XZ) ? ?㭪樨 “class UUserWidget * __cdecl CreateWidget<class UUserWidget,class UWorld>(class UWorld *,class TSubclassOf,class FName)” (??$CreateWidget@VUUserWidget@@VUWorld@@@@YAPEAVUUserWidget@@PEAVUWorld@@V?$TSubclassOf@VUUserWidget@@@@VFName@@@Z).

MyHUD.cpp.obj : error LNK2019: ??뫪? ?? ??ࠧ??襭??? ???譨? ᨬ??? “__declspec(dllimport) public: void __cdecl UUserWidget::AddToViewport(int)” (_imp?AddToViewport@UUserWidget@@QEAAXH@Z) ? ?㭪樨 “protected: virtual void __cdecl AMyHUD::BeginPlay(void)” (?BeginPlay@AMyHUD@@MEAAXXZ).

MyHUD.cpp.obj : error LNK2019: ??뫪? ?? ??ࠧ??襭??? ???譨? ᨬ??? “__declspec(dllimport) public: static class UUserWidget * __cdecl UUserWidget::CreateWidgetInstance(class UWorld &,class TSubclassOf,class FName)” (_imp?CreateWidgetInstance@UUserWidget@@SAPEAV1@AEAVUWorld@@V?$TSubclassOf@VUUserWidget@@@@VFName@@@Z) ? ?㭪樨 “class UUserWidget * __cdecl CreateWidget<class UUserWidget,class UWorld>(class UWorld *,class TSubclassOf,class FName)” (??$CreateWidget@VUUserWidget@@VUWorld@@@@YAPEAVUUserWidget@@PEAVUWorld@@V?$TSubclassOf@VUUserWidget@@@@VFName@@@Z).

why is the problem my code
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

include “CoreMinimal.h”
include “GameFramework/HUD.h”
include “MyHUD.generated.h”

UCLASS()
class TECHWAR_API AMyHUD : public AHUD
{
GENERATED_BODY()

protected:
virtual void BeginPlay() override;

public:
TSubclassOf HUDWidgetClass;
class UUserWidget* HUDWidget;
};

cpp:
// Fill out your copyright notice in the Description page of Project Settings.

include “MyHUD.h”
include “Blueprint/UserWidget.h”
include “Engine/Canvas.h”

void AMyHUD::BeginPlay()
{
Super::BeginPlay();

HUDWidget = CreateWidget<class UUserWidget>(GetWorld(), HUDWidgetClass);
HUDWidget->AddToViewport();

}

Hello! You need to add “UMG” to the PublicDependencyModuleNames array in your *.build.cs file

Thanks man!!! you save my time

1 Like