-
-
Notifications
You must be signed in to change notification settings - Fork 305
RPCs vs Fields
Both of them, send information. So, which one should you use?
Here is a synopsis of their differences:
- 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
- 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)
- 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.
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.
Getting Started
Network Contract Wizard (NCW)
Remote Procedure Calls (RPCs)
Unity Integration
Basic Network Samples
Scene Navigation
Master Server
Netcoding Design Patterns
Troubleshooting
Miscellaneous
-
Connection Cycle Events
-
Rewinding
-
Network Logging
-
Working with Multiple Sockets
-
Modify Master and Standalone servers
-
NAT Hole Punching
-
UDP LAN Discovery
-
Offline Mode
-
Ping Pong
-
Lobby System
-
Upgrading Forge Remastered to Develop branch or different version
-
Forge Networking Classic to Remastered Migration Guide
-
Script to easily use Forge Networking from sources
-
Run Two Unity Instances with Shared Assets for Easiest Dedicated Client Workflow