0

MyActor.h

UCLASS()
class FPS_API AMyActor: public AActor
{
    GENERATED_BODY()
...
public:
    UFUNCTION(NetMulticast, Reliable)
    void MulticastRPCMyFunction();
...
}

MyActor.cpp

void AMyActor::MulticastRPCMyFunction()
{
    UE_LOG(LogTemp, Log, TEXT("Message"));
}

When i compile my project, i can check the error message below. Compile error

*.gen.cpp.obj : error LNK2005: "public: void __cdecl *::MulticastRPCMyFunction(void)" (?MulticastRPCMyFunction@*@@QEAAXXZ) already defined in *.cpp.obj
BenjaFriend
  • 664
  • 3
  • 13
  • 29
김진우
  • 161
  • 3
  • 12

1 Answers1

1

With networked functions (in your case the NetMulticast metadata) you do not name the function the same thing in the Cpp file as the header file because it gets generated by UHT (hence the linker error about it already being defined).

In your case your Cpp file would need to look like this:

void AMyActor::MulticastRPCMyFunction_Implementation()
{
    UE_LOG(LogTemp, Log, TEXT("Message"));
}

Notice the _Implementation addition to the function name.

If you ever add the WithValidation metadata, then you would need another function with _Validate added to the end of the function name.

BenjaFriend
  • 664
  • 3
  • 13
  • 29