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

when i add this in to my .h file it will not compile UFUNCTION(reliable, server)



UFUNCTION(reliable, server)//set this to a server function
void ServerShouldSprint(bool bSprint);


take this out and it compiles UFUNCTION(reliable, server)
wondering why and what’s causing this error? anyone have an idea?

Compiler error is?

Did you also create the _Implementation of it as well?

It really does not give an error. It just does not compile, says failure and will not save the .dll Any time i try to add this to any function it will not compile UFUNCTION(Reliable, Server) or UPROPERTY(Replicated).

I read where we should use FPROPERTY() but that does not work, If i use either of those 2 settings i cant get it to compile. Take them out it compiles fine.

Do i need to set up macros somewhere in vs2017?

This is a must read http://cedric-neukirchen.net/Downloads/Compendium/UE4_Network_Compendium_by_Cedric_eXi_Neukirchen.pdf

Very nice read. Nice to see it basically the same as udk :). I’m going after not using much blue prints. Do as much as i can in code :).

If i take the Reliable, Server OUT it will compile.
This function needs to be this way. i also have a few more functions i need to set the same way. When i do, same stuff happens as above. These few functions that i need (Reliable, Server) must be that or things will not work right.

Any help would be great thanks.



UFUNCTION(reliable, server)//set this to a server function
void ServerShouldSprint(bool bSprint);
void ServerShouldSprint_Implementation(bool bSprint);  //<--- You have this function too?  This is described in Cedric's PDF. 


The _Implementation method is the one that is actually defined in the .cpp

Hmmm…just thought of something.

You need to be sure the below include is setup. I put mine a header that is included in every cpp.


// This is NOT included by default in an empty project! It's required for replication and setting of the GetLifetimeReplicatedProps
#include "Net/UnrealNetwork.h"


hmm, was thinking earlier maybe its because i have not put in the online server stuff yet? Will add see if that helps, thanks

I added the above files and still error, Here is the error i am getting.
Colored for easier reading.



1>FUUnrealCharacter.gen.cpp.obj : warning LNK4006: "public: void __cdecl AFUUnrealCharacter::ServerIsSprinting(bool)" (?ServerIsSprinting@AFUUnrealCharacter@@QEAAX_N@Z) already defined in FUUnrealCharacter.cpp.obj; second definition ignored
1> Creating library C:\Users\********\Documents\Unreal Projects\FUUnreal\Intermediate\Build\Win64\UE4Editor\Development\FUUnreal\UE4Editor-FUUnreal.lib and object C:\Users\********\Documents\Unreal Projects\FUUnreal\Intermediate\Build\Win64\UE4Editor\Development\FUUnreal\UE4Editor-FUUnreal.exp
1> [32/33] UE4Editor-FUUnreal.dll
1>FUUnrealCharacter.gen.cpp.obj : error LNK2005: "public: void __cdecl AFUUnrealCharacter::ServerIsSprinting(bool)" (?ServerIsSprinting@AFUUnrealCharacter@@QEAAX_N@Z) already defined in FUUnrealCharacter.cpp.obj
1> Creating library C:\Users\********\Documents\Unreal Projects\FUUnreal\Intermediate\Build\Win64\UE4Editor\Development\FUUnreal\UE4Editor-FUUnreal.suppressed.lib and object C:\Users\********\Documents\Unreal Projects\FUUnreal\Intermediate\Build\Win64\UE4Editor\Development\FUUnreal\UE4Editor-FUUnreal.suppressed.exp
1>FUUnrealCharacter.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl AFUUnrealCharacter::ServerIsSprinting_Implementation(bool)" (?ServerIsSprinting_Implementation@AFUUnrealCharacter@@UEAAX_N@Z)
1>FUUnrealCharacter.gen.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl AFUUnrealCharacter::ServerIsSprinting_Implementation(bool)" (?ServerIsSprinting_Implementation@AFUUnrealCharacter@@UEAAX_N@Z)
1>C:\Users\********\Documents\Unreal Projects\FUUnreal\Binaries\Win64\UE4Editor-FUUnreal.dll : fatal error LNK1120: 1 unresolved externals
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.MakeFile.Targets(49,5): error MSB3073: The command ""C:\Program Files\Epic Games\UE_4.25\Engine\Build\BatchFiles\Rebuild.bat" FUUnrealEditor Win64 Development -Project="C:\Users\********\Documents\Unreal Projects\FUUnreal\FUUnreal.uproject" -WaitMutex -FromMsBuild" exited with code -1.
1>Done building project "FUUnreal.vcxproj" -- FAILED.


If i take the Reliable, Server OUT it will compile. I can leave this in UFUNCTION() it will compile fine.
Same thing goes for UPROPERTY(Replicated).

the “Net/UnrealNetwork.h” just add it into your project.h file only. You do not need it in ever cpp files .h file.
Got everything from above added and it all compiles fine, until i add in Reliable, Server

Stumped at the moment, missing something somewhere.

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.

Thanks for the explanation. I figured out what i did wrong it was the way i was using



UFUNCTION(Reliable, Server, WithValidation)//set this to a server function
void Server_IsSprinting();
void Server_IsSprinting_Implementation();
bool Server_IsSprinting_Validate();


problem was i was putting Server_IsSprinting(); into the .cpp file. Now that i figured out how this works, this is nice. Plus i was calling wrong function from Server_IsSprinting_Implementation();

Hey thanks a ton, nice to get this working.