Replicated UFUNCTION parameter restrictions

I’m having an issue currently which I can’t quite get my head around, I’m trying to pass an array as a parameter to a function which should only run on owning client.

When I define it like this:

UFUNCTION(Client, Reliable)
void Client_ScoreChangedUpdateHUD(TArray<FPlayerScores> playerScoreboard);

It says that it wants the array passed as a const reference, similar to how it wants them passed if it needs to be blueprint visible

But when I define it like this:

UFUNCTION(Client, Reliable)
void Client_ScoresChangedUpdateHUD(const TArray<FPlayerScores>& playerScoreboard)

It throws this linkage error:

 error LNK2005: "protected: void __cdecl AIslanderPlayerController::Client_ScoresChangedUpdateHUD(class TArray<struct FPlayerScores,class FDefaultAllocator> const &)" (?Client_ScoresChangedUpdateHUD@AIslanderPlayerController@@IEAAXAEBV?$TArray@UFPlayerScores@@VFDefaultAllocator@@@@@Z) already defined in IslanderPlayerController.cpp.obj

Note that if I take out the UFUNCTION(Client, Reliable) - then it’s more than happy to compile, but when it’s a replicated function, it doesn’t like the array either as a pass by value, or as a pass by const reference.

So how do I pass an array as a parameter to a replicated function?

In your CPP file you should name the function as:

void Client_ScoresChangedUpdateHUD_Implementation(const TArray& playerScoreboard)

The reason is that the UE4 build system automatically creates:

void Client_ScoresChangedUpdateHUD(const TArray& playerScoreboard)

Hence, it complains about two definitions being there.

1 Like

You’re absolutely right, thanks for that. Though if any staff see’s this would be nice to get the documentation updated, as that’s missing from the example given for a client function here: A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums