Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Unresolved External Symbol When Trying to Create an Abstract Actor Class With a Pure Virtual Function

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"
 class TESTING_API AInteractableActor : public AActor
     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"

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)

Any clues on how to fix this?

Product Version: UE 4.8
more ▼

asked Aug 10 '15 at 02:25 AM in C++ Programming

avatar image

1 2 3 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Actors & Objects can't have pure virtual functions in them. The reason is that the UClass for those objects needs to create the CDO (class default object). This happens even for Abstract classes. It's pretty key to how the UObject property information is copied from parent classes to child classes. The best you can do to mimic pure virtual behavior is to assert in the abstract class implementation.

more ▼

answered Aug 10 '15 at 09:22 PM

avatar image

joeGraf STAFF
1.5k 35 12 69

avatar image Katsura Aug 21 '15 at 09:15 AM

Could you explain to me what you mean by asserting in the abstract class implementation, please? I don't understand why, however I got the code to function as I wanted it to by changing some things in the InteractableActor.h file and cleaning my project. The code is here: https://github.com/xxyxxyz/UnrealEngine-4-InteractableActor-Class/tree/master/Source

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Here's the code I mean

 virtual void Interact() { check(0 && "Subclasses must implement this and not call Super to the base class"); }
more ▼

answered Aug 21 '15 at 01:38 PM

avatar image

joeGraf STAFF
1.5k 35 12 69

avatar image Katsura Aug 21 '15 at 01:52 PM

Thanks. Does this mean that the code I have that's currently functioning is only functioning because of a bug?

avatar image joeGraf STAFF Aug 21 '15 at 05:45 PM

I thought you said it wasn't compiling? If it is, then ignore this. This will allow you to treat the class as abstract base class without the virtual foo() = 0;

avatar image Katsura Aug 21 '15 at 05:48 PM

Sorry if I wasn't clear. It wouldn't compile with the code I provided in the main post however the code in the Github link in one of my previous comments does compile and function appropriately.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question