When adding in UFUNCTION(reliable, server) causes compile error, why?

Let’s pull this apart. The compiler doesn’t lie to you, so learning to read the errors will help you in the future.



FUUnrealCharacter.gen.cpp.obj : error LNK2005: "public: void __cdecl AFUUnrealCharacter::ServerIsSprinting(bool)" (?ServerIsSprinting@AFUUnrealCharacter@@QEAAX_N@Z) already defined in FUUnrealCharacter.cpp.obj


This means you have AFUUnrealCharacter::ServerIsSprinting defined twice, either in your .cpp or .h file. This can be a bad code gen if you’ve been marking it as a UFUNCTION and then removing it, so sometimes a rebuild will fix these issues - but often times it’s user error and the method is defined/implemented twice. If you’ve verified it’s not defined twice - then do a rebuild.



FUUnrealCharacter.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl AFUUnrealCharacter::ServerIsSprinting_Implementation(bool)" (?ServerIsSprinting_Implementation@AFUUnrealCharacter@@UEAAX_N@Z)


Unresolved external symbol means you defined something, but never implemented it. This can be a bit tricky with UE code as replicated methods require the following structure



// In MyCode.h
UFUNCTION(Server, Reliable)
void MyServerMethod(int a, bool b);

// In MyCode.cpp
void MyServerMethod_Implementation(int a, bool b)
{
   // Do stuff
}


So you DEFINE the method like normal, but the IMPLEMENTATION has to have the “_Implementation” moniker added to it. This is because the UE Header Tool will fill out the original “MyServerMethod” define with some boilerplate code and add a new version “MyServerMethod_Implementation” that the user is meant to override.

Also make sure your header file has the “MyHeaderFile.generated.h” included or you won’t actually get the generated code added to your own code.