x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: UE 4.10
Tags:
more ▼

asked Feb 28 '16 at 05:22 AM in C++ Programming

avatar image

Hennez
197 16 15 26

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Feb 28 '16 at 09:22 AM

avatar image

cageman
645 29 33 64

avatar image Hennez Feb 28 '16 at 12:15 PM

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: https://wiki.unrealengine.com/Replication

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question