Usefulness of passing const references to RPCs

Hi everybody,

Maybe it’s a stupid idea, but I was wondering if there was a real interest to declare a parameter for an RPC as const reference, as I guess internally the data is copied anyway to be passed on the network.
I guess this is still useful to avoid one extra copy of the data, but i was wondering if you guys had an idea on the matter.

for example

UFUNCTION(Server, Reliable)
void Server_SetPlayerInfo(const FPlayerInfo& PlayerInfo);

vs

UFUNCTION(Server, Reliable)
void Server_SetPlayerInfo(FPlayerInfo PlayerInfo);

FPlayerInfo being a USTRUCT composed of a few FStrings

const itself does not prevent copying anything. All it’s saying is: “This function is not allowed to modify the state of this variable”, even if it’s a copy. It’s most useful to make sure, you don’t accidentally set anything in it unwanted.

By using reference, you probably save a copy: the data is transmitted to the server through the network, the server constructs the struct, then passes it to your function. If you don’t use a reference, then I believe one more copy is created on the server side.

So yes, I think most usually you’ll want to have a const reference in RPCs.