Function replication not working

I have recently started adding multiplayer to my project and looked at different guides on replication, variables work well so far i think. Now I started testing implementing functions and they don’t seem to work no matter what guide I use.

AEntity.h

UFUNCTION(Server, Reliable, WithValidation)
void ServerAttack();

##AEntity.cpp##

void AEntity::ServerAttack_Implementation(){
if(!Attacking){
Attacking = true;
}
}

bool AEntity::ServerAttack_Validate(){
return true;
}

ServerAttack_Validate function doesn’t throw any errors while ServerAttack_Implementation keeps throwing errors that it is not a member of AEntity. It throws an error to GENERATED_BODY() saying class “AEntity” has no member “ServerAttack_Implementation”

I have “UnrealNetwork.h” included in the cpp file

I have the same problem - have you managed to solve it?

Change AEntity.h

UFUNCTION(Server, Reliable, WithValidation)
void ServerAttack();
virtual void ServerAttack_Implementation();
virtual bool ServerAttack_Validate();

But still If I want to replicate to all platers in SerwerAttack I have to call Multicast function right? (at lest this is the only thing that’s working for me)

As of UE 4.15 the compile system adds the implementation and validation definitions for you. Making the code for the header as follows:

AEntity.h

void Attack();

UFUNCTION(reliable, server, WithValidation)
void ServerAttack();

AEntity.cpp

void AEntity::Attack()
{
    // If this next check succeeds, we are *not* the authority, meaning we are a network client.
    if (Role < ROLE_Authority)
    {
        ServerAttack();
    }
}
 
bool AEntity::ServerAttack_Validate(l)
{
    return true;
}
 
void AEntity::ServerAttack_Implementation()
{
    // This function is only called on the server (where Role == ROLE_Authority), called over the network by clients.
    // Inside that function, Role == ROLE_Authority, so it won't try to call Attack() again.
    Attack();
}

For anyone who is still looking for a solution to this problem it solved for me changing the macro GENERATED_BODY() by GENERATED_UCLASS_BODY() then it will recognize the _Implementation and _Validate functions in the .cpp without creating the virtual declarations in the .h.

Also note when you change the macro you will need to add “const FObjectInitializer& ObjectIntializer” parameter to your class constructor ONLY in the cpp file.

Hope it helps!