Adding replication causes missing vtable linker error

Trying to learn how to get property replication working in C++, but having problems.

Steps to reproduce:

  1. In GUI, create new C++ subclass of Actor
  2. Add in anything and tag it with UPROPERTY(Replicated)
  3. Compile fails with error below
Info Running Mono...
Info 
Info Setting up Mono
Info /Volumes/Macintosh HD/Users/Shared/UnrealEngine/4.7/Engine /Volumes/Macintosh HD/Users/Shared/UnrealEngine/4.7/Engine/Binaries/Mac
Info Compiling with Mac SDK 10.10
Info Parsing headers for MyProject3Editor
Info Reflection code generated for MyProject3Editor
Info Performing 3 actions (8 in parallel)
Info [1/3] Compile MyProject3.generated.cpp
Info [2/3] Compile MyActor1.cpp
Info [3/3] Link UE4Editor-MyProject3-4095.dylib
Info Undefined symbols for architecture x86_64:
Info   "vtable for AMyActor1", referenced from:
Info       AMyActor1::AMyActor1() in MyActor1.cpp.o
Info       AMyActor1::AMyActor1() in MyActor1.cpp.o
Info   NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
Info ld: symbol(s) not found for architecture x86_64
Info clang: error: linker command failed with exit code 1 (use -v to see invocation)
Info -------- End Detailed Actions Stats -----------------------------------------------------------
Info ERROR: UBT ERROR: Failed to produce item: /Volumes/Macintosh HD/Users/kevin/Documents/Unreal Projects/UE4Sandbox/Binaries/Mac/UE4Editor-MyProject3-4095.dylib
Info Cumulative action seconds (8 processors): 0.00 building projects, 8.88 compiling, 0.00 creating app bundles, 0.00 generating debug info, 0.13 linking, 0.00 other
Info UBT execution time: 14.46 seconds

Header

class MYPROJECT3_API AMyActor1 : public AActor
{
	GENERATED_BODY()
public:	
	AMyActor1();
	virtual void BeginPlay() override;
	virtual void Tick( float DeltaSeconds ) override;
	UPROPERTY(Replicated)
	TArray IntegerArray;	
};

Implementation

AMyActor1::AMyActor1()
{
	PrimaryActorTick.bCanEverTick = true;
}
void AMyActor1::BeginPlay()
{
	Super::BeginPlay();
}
void AMyActor1::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );
}
1 Like

Are you missing the UCLASS macro in the actual header file or just not showing it ?

It’s there, I just forgot to paste it into the post.

Did you remember to set bReplicates = true; in the constructor?

The TArray is a uint32. It just didn’t render properly in the post because of the angle brackets. Though, it really doesn’t matter what the type is. I have tried making the replicated property a uint32, bool, etc.

I have tried with it set and unset, both cases failed. Although, would it really matter at this point in the compilation phase? I don’t think UHT does any introspection beyond definitions…

What type of tarray use?
int32?

And you need to tell engine how your vars replicate. Like this

void AMyActor1::GetLifetimeReplicatedProps(TArray<FLifetimeProperty> &OutLifetimeProps) const
{
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);
	DOREPLIFETIME(AMyActor1, IntegerArray);
}

If you don`t set replicates to true it will give compiler errors as well.

There is your problem.

UPROPERTY(Replicated)
TArray IntegerArray;

You forgot the template argument.

UPROPERTY(Replicated)
TArray<int32> IntegerArray;

Hope it helps :slight_smile:

Tried out your solution again, Detech, and it does work! I must have had a typo. All I needed to do was add a function implementation for GetLifetimeReplicatedProps. I wish the compiler would have told me that’s what it wanted… If you make your comment an answer, I’ll mark it as such.