Replicating variables in C++

I’m trying to replicate an actor reference in my game, but whenever I try to make the variable replicated, it won’t compile. Here’s what I have:


UPROPERTY(Replicated)
class AActor* Target;

This is exactly what the docs say to do. But every time I try to compile with “Replicate” in the code, I get a compile error. This is in the message log that appears;


Info Creating makefile for hot reloading MAWN (ini files are newer that UBTMakefile)
Info Compiling game modules for hot reload
Info Performing 1 actions (9 in parallel)
Info [1/1] Link UE4Editor-MAWN-8104.dll
Info    Creating library C:\Users\NAME\Documents\Unreal Projects\MAWN\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-MAWN-8104.lib and object C:\Users\NAME\Documents\Unreal Projects\MAWN\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-MAWN-8104.exp
Error Explosion.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl AExplosion::GetLifetimeReplicatedProps(class TArray<class FLifetimeProperty,class FDefaultAllocator> &)const " (?GetLifetimeReplicatedProps@AExplosion@@UEBAXAEAV?$TArray@VFLifetimeProperty@@VFDefaultAllocator@@@@@Z)
Error MAWN.generated.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl AExplosion::GetLifetimeReplicatedProps(class TArray<class FLifetimeProperty,class FDefaultAllocator> &)const " (?GetLifetimeReplicatedProps@AExplosion@@UEBAXAEAV?$TArray@VFLifetimeProperty@@VFDefaultAllocator@@@@@Z)
Error C:\Users\NAME\Documents\Unreal Projects\MAWN\Binaries\Win64\UE4Editor-MAWN-8104.dll : fatal error LNK1120: 1 unresolved externals
Info ERROR: UBT ERROR: Failed to produce item: C:\Users\Name\Documents\Unreal Projects\MAWN\Binaries\Win64\UE4Editor-MAWN-8104.dll
Info Total build time: 4.36 seconds


Everything works fine if it isn’t there. I’m trying to get this variable on an APawn but I’ve tried it on an ACharacter with the exact sime result. I can’t find a fix for this anywhere.

Hey, this just means, that you need to implement the



AExplosion::GetLifetimeReplicatedProps(class TArray<class FLifetimeProperty,class FDefaultAllocator> &) const


The wiki entry https://wiki.unrealengine.com/Replication also tells you that under “Actor Property Replication” (:

To expand on that, you need to make sure you call



Super::GetLifetimeReplicatedProps( ReplicatedProps );


and also replicate your variables using the macro



DOREPLIFETIME(Target);


inside of the function scope.

You’ll also have to #include UnrealNetwork.h in your .cpp to get the above to compile.