Download

Why declaring a function with Macro "UFUNCTION(Server, reliable)" causes Link Failure when building?

I was following the tutor (https://docs.unrealengine.com/zh-CN/…art/index.html) to make a Network game sample, after all the code have been prepared, I wanted to build it for final test. But it displayed the message below:

The function with problem was declared as follows:



// Declaration:
(protected)
UFUNCTION(Server, reliable)
        void HandleFire();
// Definition:
void ANetworkTestCharacter::HandleFire()
{
    FVector spawnLocation = GetActorLocation() + (GetControlRotation().Vector() * 100.0f) + (GetActorUpVector() * 50.0f);
    FRotator spawnRotation = GetControlRotation();

    FActorSpawnParameters spawnParameters;
    spawnParameters.Instigator = Instigator;
    spawnParameters.Owner = this;

    ANetworkTestProjectile* spawnedProjectile = GetWorld()->SpawnActor<ANetworkTestProjectile>(spawnLocation, spawnRotation, spawnParameters);
}


After checking the documentions, I realize that this macro functions by making a new function with “_Implitation” added to the end, and the failure message indicates that a duplicated “HandleFire()” was declared, which I double checked with Global Search System in the Vusial Studio and it’s not. The UnrealBuildTool must have forgot to add “_Implitation” to the function name for some reason.

Is this supposed to be a bug, or something I didn’t configure properly?
(By the way, both 4.23.1, 4.24.2 are tested, and “UFUNCTION(Server, unreliable)”, “UFUNCTION(Client, reliable)”, “UFUNCTION(Client, unreliable)” are all tested, all the same.

When UHT tool see UFUNCTION(Server, reliable) that mean’s, you give access to client owner to call this function, but implementation should be on server side, therefore you don’t need to create a body for “HandleFire” but for “HandleFire_Implementation” in cpp file. Like this:
void ANetworkTestCharacter::HandleFire_Implementation() Then, when you need to client to call this function on a server, just call HandleFire().

I was looking for the same error, thank you for the answer .