Server side RPC problems

I have an RPC I’m trying to convert from BP to C++ that is just not behaving well.

I have defined:

UFUNCTION(Server, WithValidation, Reliable, Category = Weapon);
void AttackServer();
bool AttackServer_Validate();
void AttackServer_Implementation();

void AMedievalCharacter::AttackServer_Implementation() {

bool AMedievalCharacter::AttackServer_Validate() {
return true;

which keeps telling me:

C:/Users/jlatta/Documents/Unreal Projects/medieval/Source/Medieval/MedievalCharacter.h(56) : Function return type: Missing variable type

I’ve tried adding a variable to pass in, setting it to virtual functions, but no matter what that error pops up. If I take out WithValidation, it actually tells me that WithValidation is required for every Server RPC. I’ve tried adding in the base AttackServer function, same thing. We really need some documentation on this, the official docs are very dated.

I’m using 4.9.1

I think you need to name the functions ‘ServerAttack’ instead of AttackServer.

Same issue :frowning:

i don’t believe you need to define:

bool AttackServer_Validate();
void AttackServer_Implementation();

but this is based on personal experience so far, try removing them from the header

Still same issue. As of 4.7, I do believe that you actually need to define the _Validate and _Implementation.

Okay well I copied some code from shooter game over to here and it just started magically working. Works for me I guess? I didn’t include the _Implementation and _Validate in the header, there is some very confusing info on the net haha. I guess in 4.7 they took that functionality out, then put it back in with 4.8?

hm im using 4.9 atm and it seems to work without defining them.

now i gotta go mess with this

The _Validate and _Implementation definitions should be automatically generated by the UFUNCTION() call. So if you have

UFUNCTION(Server, WithValidation, Reliable, Category = Weapon);
void AttackServer();

in you .h file, all you need is

void AMedievalCharacter::AttackServer_Implementation() { … }
bool AMedievalCharacter::AttackServer_Validate() { … }

in your .cpp file. See this wiki article

SetSomeBool() is a local function, but ServerSetSomeBool() is an RPC. All he has defined is ServerSetSomeBool_Validate() and ServerSetSomeBool_Implementation()

Close but not quite, it actually depends on the GENERATED_ class type you’re using.

If you’re using GENERATED_UCLASS_BODY() - then you don’t define the functions, but if you’re using GENERATED_CLASS() then you do have to. Also, I think they need to be virtual functions but that might not be a requirement. In 4.7 and above, any new classes you create through the wizard will use GENERATED_BODY() by default, but any classes brought forward from previous versions of the engine will still have GENERATED_UCLASS_BODY()

So so long as OP is using GENERATED_BODY(), the code is correct. Try declaring the latter-two functions as virtual instead, just in case.

Ah, thanks for the clarification.

Always learn a lot from these threads, thanks guys. She’s a fresh 4.9 project, so no problems with GENERATED_BODY(). Everything is working now !

The problem is the semicolon after the UFUNCTION
Remove the semicolon between the macro and your function and it should work.

Thank you sir!