Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

RPCs vs Fields

TheYellowArchitect edited this page Feb 5, 2021 · 3 revisions

Both of them, send information. So, which one should you use?
Here is a synopsis of their differences:

RPCs

  • Collective - Received together in a function, makes for clean code (Optimal for Structs)
  • Reliable - You are certain the RPC function will be called (hence has some overhead)
  • Header - RPCArgs have meta-data inside RPCInfo, including the NetworkingPlayer and timestep
  • No Automatic Interpolation
  • Send Rate - Instantly

Fields

  • Individualistic - Receiving a variable at a time. No packing or serialization/deserialization (Optimal for single variables)
  • Unreliable - meant for fast unreliable data (e.g. position/rotation), so you don't care if some get lost in the way, if a few more can make it there
  • NoHeader - Winning those few bytes!
  • Automatic Interpolation Possible
  • Send Rate - Tick-Rate (networkObject.UpdateInterval)

Notes:

  • Fields, under the hood, are grouped together when about to be sent.
    RPCs are sent immediately with whatever data they have, so it is recommended to group/gather a lot of data together with RPCs. There is a reason grouping happens; to avoid sending a lot of individual data updates!
  • RPCs are Reliable, yet, they can become Unreliable. This comes with the extreme use-case of being tiny bit faster (but you can miss entire structs from the network!)
  • Fields' interpolation, from [0,1], will never reach 1. Because of Unity, it will reach 0.999 or whatever. Take care of this edge-case.

What about Speed?!

It doesn't matter
Hear me out. RPCs are instantly sent. Fields? You can drop their UpdateInterval close to 0, sure. Both are the same, theoritically. The difference is honestly a frame or two? Yet, there is the issue of network congestion, tl;dr: too many packets on the network The faster you send, the worse it gets (increasing ping/latency) So, you will always be limited by ping, latency, whatever, you will never have perfect transmission.

The difference of RPCs and Fields, by turning RPCs to unreliable, and Fields to 0 tick-rate, are just too little to consider. There are more important things to focus on your network design, surely, than shaving off 1 to 2 frames. The difference is less than negligible.
E.g. imagine losing 100% reliability of functions executing, and having to write code, to cache if a function has ran or not.

Consider for example, the technique of snapshot interpolation, which, being in that case, only 50~100 ms behind, doesn't make it obvious a player is behind. Surely, more important than winning negligible speed, and likely losing it via ping.

In most games, the difference between RPCs and Fields, really is negligible, to the point it's a stylistic choice. Whatever you feel more comfortable with. Focus on the netcoding design, instead of speed.

Home

Getting Started
Network Contract Wizard (NCW)
Network Object
Remote Procedure Calls (RPCs)
Unity Integration
Basic Network Samples
Scene Navigation
NetWorker
Master Server
Web Server
Netcoding Design Patterns
Troubleshooting
Miscellaneous
Forge Networking Alloy
Steamworks
Clone this wiki locally