Trying to understand some more basic concepts, to get me going on the multiplayer. I have watched videos and read documentation, but they don’t properly cover this kind of understanding.
If I want to do a function Only on client, or Only on server, does the below screenshot achieve that?
If I have a reliable RPC for owning client, is it guaranteed to execute only on the owning client, no matter where it’s called, and will it execute only once? So for example I have 1 listen server and 2 clients, will that RPC execute only once when I call it, and only on the owning client? If no, how can I achieve that?
Same question for the server RPC.
A more specific question, say, I want to change the player movement speed, but do it in a way that player doesn’t feel lag (Doesn’t have to wait for server validation). Is the below screenshot the correct way to do it?
Yes, these functions would be called on Server and Client as you named them. You should also keep in mind, that the Client Function will be called for each client by each client. For example, I have 2 clients and 1 server client (listen server). Here is a sketch of what actors would call what functions. Green calls are simulated on Client 1, blue calls on Client 2, and red calls on Server.
This is from UE4 Network Compendium by Cedric ‘eXi’ Neukirchen
It will be executed as many times as you call it. I would need more info to help what you exactly want to achieve here. Generally, if some logic needs to call a client RPC once, just check that on the server (use do once or boolean logic).
It is almost correct. If you want the client to predict movement change, the original ClientEvent doesn’t need to be RPC, but just a regular event called from that client(for example, pressing the Sprint key). It would technically work as is, but as it is now, it gives off an assumption that it would be called from the server, which would mean, you aren’t predicting the move speed like you stated, but just updating it from the server.
Thanks for the response. Before I commit to turning the rest of my code into multiplayer, could you tell me if I did the below screenshots right? So that I know that I understood everything correctly.
The goal currently is to replicate sprinting, in a way that character doesn’t feel lag.
I tested and this works, but working doesn’t necessarily mean that I did it correctly.
P.S. I know that for this simple speed change it would be better to not use tick, but I’m gonna use much more complicated calculations on client to set target speed, and this will make things much easier, and the branch check ensures it will fire the server RPC only when necessary.
Your code should work and it seems right if you must use tick. If you are planning on using a listen server (one client is the server), then you should have a HasAuthority check before that RPC (and connect false/remote to RPC), because the Server Client will already set its speed on the server and there would be no need for that RPC.