I was following this tutorial here. I made a few changes to make it a health bar.
The issue started occurring when I edited the game mode c++ file. Whenever I try to build my project I get this message:
1>------ Build started: Project: MyProject6, Configuration: Development_Editor x64 ------
1>Parsing headers for MyProject6Editor
1> Running UnrealHeaderTool "C:\Users\User\Documents\Unreal Projects\MyProject6\MyProject6.uproject" "C:\Users\User\Documents\Unreal Projects\MyProject6\Intermediate\Build\Win64\MyProject6Editor\Development\MyProject6Editor.uhtmanifest" -LogCmds="loginit warning, logexit warning, logdatabase error" -Unattended -WarningsAsErrors -installed
1>Reflection code generated for MyProject6Editor in 35.0503971 seconds
1>Performing 4 actions (4 in parallel)
1>MyProject6GameMode.cpp
1>MyProject6GameMode.gen.cpp
1>[3/4] Link UE4Editor-MyProject6.dll
1>[4/4] Link UE4Editor-MyProject6.lib
1> Creating library C:\Users\User\Documents\Unreal Projects\MyProject6\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-MyProject6.suppressed.lib and object C:\Users\User\Documents\Unreal Projects\MyProject6\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-MyProject6.suppressed.exp
1> Creating library C:\Users\User\Documents\Unreal Projects\MyProject6\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-MyProject6.lib and object C:\Users\User\Documents\Unreal Projects\MyProject6\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-MyProject6.exp
1>MyProject6GameMode.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 "class UUserWidget * __cdecl CreateWidget<class UUserWidget>(class UWorld *,class UClass *)" (??$CreateWidget@VUUserWidget@@@@YAPEAVUUserWidget@@PEAVUWorld@@PEAVUClass@@@Z)
1>MyProject6GameMode.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl UUserWidget::AddToViewport(int)" (__imp_?AddToViewport@UUserWidget@@QEAAXH@Z) referenced in function "private: virtual void __cdecl AMyProject6GameMode::BeginPlay(void)" (?BeginPlay@AMyProject6GameMode@@EEAAXXZ)
1>MyProject6GameMode.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class UUserWidget * __cdecl UUserWidget::CreateWidgetOfClass(class UClass *,class UGameInstance *,class UWorld *,class APlayerController *)" (__imp_?CreateWidgetOfClass@UUserWidget@@SAPEAV1@PEAVUClass@@PEAVUGameInstance@@PEAVUWorld@@PEAVAPlayerController@@@Z) referenced in function "class UUserWidget * __cdecl CreateWidget<class UUserWidget>(class UWorld *,class UClass *)" (??$CreateWidget@VUUserWidget@@@@YAPEAVUUserWidget@@PEAVUWorld@@PEAVUClass@@@Z)
1>MyProject6GameMode.gen.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class UClass * __cdecl Z_Construct_UClass_UUserWidget_NoRegister(void)" (__imp_?Z_Construct_UClass_UUserWidget_NoRegister@@YAPEAVUClass@@XZ) referenced in function "class UClass * __cdecl Z_Construct_UClass_AMyProject6GameMode(void)" (?Z_Construct_UClass_AMyProject6GameMode@@YAPEAVUClass@@XZ)
1>C:\Users\User\Documents\Unreal Projects\MyProject6\Binaries\Win64\UE4Editor-MyProject6.dll : fatal error LNK1120: 4 unresolved externals
1>ERROR : UBT error : Failed to produce item: C:\Users\User\Documents\Unreal Projects\MyProject6\Binaries\Win64\UE4Editor-MyProject6.dll
1>Total build time: 333.47 seconds (Local executor: 0.00 seconds)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.MakeFile.Targets(44,5): error MSB3075: The command ""C:\Program Files\Epic Games\UE_4.18\Engine\Build\BatchFiles\Build.bat" MyProject6Editor Win64 Development "C:\Users\User\Documents\Unreal Projects\MyProject6\MyProject6.uproject" -waitmutex" exited with code 5. Please verify that you have sufficient rights to run this command.
1>Done building project "MyProject6.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========
Here is my c++ code in the Gamemode file:
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
#include "MyProject6GameMode.h"
#include "MyProject6Character.h"
#include "UObject/ConstructorHelpers.h"
#include "Blueprint/UserWidget.h"
#include "Runtime/Engine/Classes/Kismet/GameplayStatics.h"
#include "MyProject6.h"
void AMyProject6GameMode::BeginPlay()
{
Super::BeginPlay();
AMyProject6Character* MyCharacter = Cast<AMyProject6Character>(UGameplayStatics::GetPlayerPawn(this, 0));
if(PlayerHUDClass != nullptr)
{
CurrentWidget = CreateWidget<UUserWidget>(GetWorld(), PlayerHUDClass);
if(CurrentWidget != nullptr)
{
CurrentWidget->AddToViewport();
}
}
}
AMyProject6GameMode::AMyProject6GameMode()
{
// set default pawn class to our Blueprinted character
static ConstructorHelpers::FClassFinder<APawn> PlayerPawnBPClass(TEXT("/Game/ThirdPersonCPP/Blueprints/ThirdPersonCharacter"));
if (PlayerPawnBPClass.Class != NULL)
{
DefaultPawnClass = PlayerPawnBPClass.Class;
}
}
And here is my .h file for the game mode file:
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "MyProject6GameMode.generated.h"
UCLASS(minimalapi)
class AMyProject6GameMode : public AGameModeBase
{
GENERATED_BODY()
//Overrides BeginPlay from base class
virtual void BeginPlay() override;
public:
AMyProject6GameMode();
protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Health", Meta = (BlueprintProtected = "true"))
TSubclassOf<class UUserWidget> PlayerHUDClass;
UPROPERTY()
class UUserWidget* CurrentWidget;
};
Any help would be appreciated!