Replicate a variable/property client->server

I started experimenting with multiplayer for my project just yesterday and it’s impressive how many things work “out of the box”. What I am trying to do now should be pretty simple too, but I’m not sure how to do it.

I just want clients to constantly send a direction-vector to the server that represents the mouse-cursor-direction in world-space. I think there is no way the server can do this by itself, because (afaik) it can’t know the position of a client’s cursor, and even if it did, it would also need to know the client’s viewport settings to make any use of it. So I want the client to have “authority” over this vector and it should be treated like any other “input” from the player controller.

The only way I can think of atm would be to write a server-function and call it from the client with the direction-value, only to set the property on the server. I would have to call that function every frame though and I suspect there is a better way to simply replicate a value from client to server. Any help?

Nope, rapidly calling an RPC to send to the server is the way to do it! You can call it less frequently than every frame if you want. Since it’s a cosmetic value (at least, I’m assuming it’s cosmetic, and not something used for authoritative decisions) I’d recommend calling it less frequently (maybe 10 times a second?) and using a smoothing/interpolation on clients (every frame) so that the value changing doesn’t look jittery.

Oh, I see :slight_smile:

Thanks a lot for answering! (Most of my questions never get answered…)

At the moment, I just need the value for rotating the player characters to their clients’ mouse cursor in a kind of top-down setting. But since this is also relevant for, let’s say, firing a gun in the right direction, I guess it’s not just cosmetic.

Anyway, it’s good to know I’m on the right track, so I don’t have to rewrite everything later.

Would you say it’s a good idea to store this value along with any values that I might add later inside a structure and send everything at once (only if needed, of course) by a single RPC call to reduce overhead? I don’t know what an UE4 package looks like, but I guess the less packages, the better the efficiency.

I have another question: Is it possible to call a function both on the client and server? The idea is to do this with a “startCrouch” function. Since the player actor is being replicated, it should be enough to call it on the server, I guess. But calling it on the client too would probably prevent a delay. At least that’s what I’m thinking.