Best RPC practices

Best practices when using RPC

I am coding a multiplayer game where the clients mouse position is tracked when using an ability (with gas), the ability executes on clients ony sice now it is all cosmetics, but after the ability ends I need the server to know the positions of the mouse throught the duration of the ability (which is a Vector2D array) so it can perform certain actions depending on the result, I don’t want the clients to perform those actions sice thay would break the client-server structure where the server is the one that does all gameplay related actions. However, I don’t think that sending a 100 ish long array using an RPC (reliable one to ensure the package is recieved) is the best idea, because it would take a lot of bandwidth. Is it better to send each position of the mouse right when it is registered in the client to the server using an unrealiable RPC? Or are there any best options to approach this problem?
Any help is welcome.
TLDR: when communicating from client to server using RPC, is it better to send a big chunck of data once using reliable RPC or split it in smaller pieces and send many of those over time with unrealiable RPC? If there is a better solution, I’ll be gratefull to know!

It really depends on what your specific game-play requires.

Now I would suggest not sending the actual mouse position but something gameplay related like player direction. Of course this might not be applicable for your mechanic.

Next I would suggest sending the data at custom rate and lower that rate as much as you can. Depending on your gameplay sending data once every 0.5 or even 1 second might be unnoticable.

Lastly I would suggest you filter your data (even if you’ve lowered your data rate) Surely there are distances and movements that are just not meaningful for your mechanic so drop (don’t send) positions/angles that are too close together. Again this should discard as as much data as possible without breaking your game.

Hope this works for you.

Thanks for the answer!
I’ll take your advice and try to optimize as much as possible the data sent

You can have each player send a reliable RPC each frame like a single Vector if that’s what you’re asking? Then each player can build the array locally. That would definitely be better than sending a large array. It won’t be too much data because if you think about it each player needs to have an ordered stream of data every frame anyway.

That is exactly what you shouldn’t do. Keep in mind that some clients might run the game at 240 FPS and some might do it in 30 fps and your server should get data at the same rate from both. Most mechanics should work fine with less than 4 RPC per second which is from 10 to 60 times less data before discarding irrelevant data.

2 Likes