So, I’m trying to create an interface class called ‘AInteractableActor’ which contains a pure virtual method named ‘Interact()’ so that I can easily add interactable actors to my game without having to program an individual cast for each type of actor I want to be able to interact with inside my PlayerCharacter class.
However, when I compile my code I’m given a linking error to do with an unresolved external symbol. This is the error output from VS:
Error 1 error LNK2019: unresolved external symbol "public: __cdecl AInteractableActor::AInteractableActor(void)" (??0AInteractableActor@@QEAA@XZ) referenced in function "public: static void __cdecl AInteractableActor::__DefaultConstructor(class FObjectInitializer const &)" (?__DefaultConstructor@AInteractableActor@@SAXAEBVFObjectInitializer@@@Z) D:\Unreal Projects\Testing\Intermediate\ProjectFiles\PlayerCharacter.cpp.obj Testing
Error 2 error LNK2001: unresolved external symbol "public: __cdecl AInteractableActor::AInteractableActor(void)" (??0AInteractableActor@@QEAA@XZ) D:\Unreal Projects\Testing\Intermediate\ProjectFiles\Testing.generated.cpp.obj Testing
Error 3 error LNK1120: 1 unresolved externals D:\Unreal Projects\Testing\Binaries\Win64\UE4Editor-Testing-8366.dll 1 1 Testing
Error 4 error : Failed to produce item: D:\Unreal Projects\Testing\Binaries\Win64\UE4Editor-Testing-8366.dll D:\Unreal Projects\Testing\Intermediate\ProjectFiles\ERROR Testing
Error 5 error MSB3073: The command ""C:\Program Files\Epic Games\4.8\Engine\Build\BatchFiles\Build.bat" TestingEditor Win64 Development "D:\Unreal Projects\Testing\Testing.uproject" -rocket" exited with code -1. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets 38 5 Testing
As far as I can tell, it’s having a problem finding the default constructor for the class for some reason.
This is the code for my InteractableActor.h:
#pragma once
#include "GameFramework/Actor.h"
#include "InteractableActor.generated.h"
UCLASS(ABSTRACT)
class TESTING_API AInteractableActor : public AActor
{
GENERATED_BODY()
public:
AInteractableActor();
UFUNCTION(BlueprintCallable, Category = Interaction)
virtual void Interact() PURE_VIRTUAL(AInteractableActor::Interact, ;);
};
And this is the class for InteractableActor.cpp:
#include "Testing.h"
#include "InteractableActor.h"
AInteractableActor::AInteractableActor()
{
}
This is the related piece of code I am running within my PlayerCharacter.cpp:
void APlayerCharacter::Use()
{
FHitResult HitResult(EForceInit::ForceInit);
if (TraceFromSelf(HitResult, 250.0f, ECollisionChannel::ECC_EngineTraceChannel1))
{
AActor* const HitActor = HitResult.GetActor();
if (HitActor)
{
AInteractableActor* InteractableActor = dynamic_cast<AInteractableActor*>(HitActor);
if (InteractableActor)
{
InteractableActor->Interact();
}
}
}
}
Any clues on how to fix this?