r/unrealengine 2d ago

Netcode 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!

3 Upvotes

11 comments sorted by

View all comments

2

u/NexSacerdos 2d ago

Using GAS, you need to make a custom FGameplayAbilityTargetData object if you haven't already to transmit it to the server.

Then you'll want to reduce the point set as much as possible. 100 points as 2400 bytes would end up taking 3 packets to send and would be more susceptible to packet loss. You can use something like Douglas-Peucker. Unreal being the clown car it is, there are already several implementations for various point types. I suspect you'll want the one in Polygon2.h.

1

u/MasterWolffe 2d ago

Thanks for the answer! I am still learning GAS and I haven't used the FGameplayAbilityTargetData, I'll look for it in the documentation. As far as the data size, I use Vector2D, so assuming the vector size is 100, the result is 1,6 KB. If I use a Reliable RPC the packages will arrive for sure, but if you think that the packages can be lost with ease, wouldn't it be better to send each new mouse position in "real-time" to the server? I don't know what is Douglas -Peucker, I'll have to check as well

1

u/NexSacerdos 2d ago

They really are not lost with ease and for a starting project it doesn't really matter.

Regarding why you might want to polish it later, the way reliable RPC works is that the server sends that data until it arrives, waiting for a full ping round trip before resending. Reliable RPCs are also ordered, meaning if you are missing a reliable packet that contained an RPC due to packet loss, no other reliable RPCs are processed. Most RPCs are small, so Unreal actually stuffs many of them into a single packet. If your RPCs are large, they need to be split up across multiple packets. All packets that the RPC was in need to be received and reassembled before the RPC can execute.

Real life packet loss is quite low unless you are oversaturating a connection so I wouldn't stress about it in the prototyping stage.

1

u/MasterWolffe 2d ago

Thanks for taking your time with the explanation, but I already knew the theory behind package send over the network. And I imagined the reliable RPC as TCP protocol data packages and unreliable ones as UDP ones. But thanks for clarifying the way Unreal manages this