WidgetAroundPawnComponent.h
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Blueprint/UserWidget.h"
#include "WidgetAroundPawnComponent.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class DARK_API UWidgetAroundPawnComponent : public UActorComponent
{
GENERATED_BODY()
//UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
UUserWidget* Widget;
public:
// Sets default values for this component's properties
UWidgetAroundPawnComponent();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
};
WidgetAroundPawnComponent.cpp
#include "WidgetAroundPawnComponent.h"
// Sets default values for this component's properties
UWidgetAroundPawnComponent::UWidgetAroundPawnComponent()
:Super()
{
PrimaryComponentTick.bCanEverTick = true;
Widget = NewObject<UUserWidget>(this, UUserWidget::StaticClass());
}
// Called when the game starts
void UWidgetAroundPawnComponent::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void UWidgetAroundPawnComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}
Build log:
1>------ Build started: Project: UE4, Configuration: BuiltWithUnrealBuildTool Win32 ------
2>------ Build started: Project: Dark, Configuration: DebugGame_Editor x64 ------
2>Parsing headers for DarkEditor
2> Running UnrealHeaderTool "C:\Unreal Projects\Dark\Dark\Dark.uproject" "C:\Unreal Projects\Dark\Dark\Intermediate\Build\Win64\DarkEditor\DebugGame\DarkEditor.uhtmanifest" -LogCmds="loginit warning, logexit warning, logdatabase error" -Unattended -WarningsAsErrors -installed
2>Reflection code generated for DarkEditor in 14.6640206 seconds
2>Building 4 actions with 4 processes...
2> [1/4] WidgetAroundPawnComponent.cpp
2> [2/4] WidgetAroundPawnComponent.gen.cpp
2> [3/4] UE4Editor-Dark-Win64-DebugGame.lib
2> Creating library C:\Unreal Projects\Dark\Dark\Intermediate\Build\Win64\UE4Editor\DebugGame\Dark\UE4Editor-Dark-Win64-DebugGame.lib and object C:\Unreal Projects\Dark\Dark\Intermediate\Build\Win64\UE4Editor\DebugGame\Dark\UE4Editor-Dark-Win64-DebugGame.exp
2> [4/4] UE4Editor-Dark-Win64-DebugGame.dll
2> Creating library C:\Unreal Projects\Dark\Dark\Intermediate\Build\Win64\UE4Editor\DebugGame\Dark\UE4Editor-Dark-Win64-DebugGame.suppressed.lib and object C:\Unreal Projects\Dark\Dark\Intermediate\Build\Win64\UE4Editor\DebugGame\Dark\UE4Editor-Dark-Win64-DebugGame.suppressed.exp
2>WidgetAroundPawnComponent.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class UClass * __cdecl UUserWidget::StaticClass(void)" (__imp_?StaticClass@UUserWidget@@SAPEAVUClass@@XZ) referenced in function "class UUserWidget * __cdecl NewObject<class UUserWidget>(class UObject *,class UClass *,class FName,enum EObjectFlags,class UObject *,bool,struct FObjectInstancingGraph *)" (??$NewObject@VUUserWidget@@@@YAPEAVUUserWidget@@PEAVUObject@@PEAVUClass@@VFName@@W4EObjectFlags@@0_NPEAUFObjectInstancingGraph@@@Z)
2>C:\Unreal Projects\Dark\Dark\Binaries\Win64\UE4Editor-Dark-Win64-DebugGame.dll : fatal error LNK1120: 1 unresolved externals
2>UnrealBuildTool : error : UBT ERROR: Failed to produce item: C:\Unreal Projects\Dark\Dark\Binaries\Win64\UE4Editor-Dark-Win64-DebugGame.dll
2> (see ../Programs/UnrealBuildTool/Log.txt for full exception trace)
2>Total build time: 25.07 seconds (Parallel executor: 0.00 seconds)
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCTargets\Microsoft.MakeFile.Targets(44,5): error MSB3075: The command ""C:\Program Files\Epic Games\UE_4.20\Engine\Build\BatchFiles\Build.bat" DarkEditor Win64 DebugGame "C:\Unreal Projects\Dark\Dark\Dark.uproject" -WaitMutex -FromMsBuild" exited with code 5. Please verify that you have sufficient rights to run this command.
2>Done building project "Dark.vcxproj" -- FAILED.
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I try many way to fix that, but just in vain, I hope someone can help me, thanks!