RPCs versus Replication and OnRep-events

Old subject but I stumbled upon it while googling this question myself. I’ve typically try to adhere to the following analogy when using an RPC or Replicated variables:

RPCs are FUNCTIONS
Replicated Variables are just VARIABLES.

Ask yourself these questions:

Do I need to know about every intermediate value of something? Use an RPC.
Do I only care about the current value, no matter it’s previous values it could have been? Use a Replicated Variable.

RPCs are just logic. They can tell clients or servers to do a specific routine. I typically only use Reliable RPCs, so that these routines are executed in order they were sent.
A replicated variable is simply state. Sure you want that state to be in sync on all the clients, but any intermediate state should not be of any importance.

Replicated variables are sent as bunches periodically. So you can set X to be X+1 multiple times in one frame, but the client will only get the final result. There is a reason that by default, OnRep_ doesn’t give you the old value. You really should not be reliant on the old value, cause it could have changed multiple times, and then the question is, did you need to know about all those intermediate values. If the answer is yes (maybe rethink your architecture), then you want an RPC where you send every value individually. It’s now become a function, a function that tells you to do specific things according to the input parameter.

6 Likes