Search Unity

Question Which is more efficient? One RPC vs multiple NetworkVariables

Discussion in 'Netcode for GameObjects' started by ktdab, Aug 28, 2022.

  1. ktdab


    Sep 22, 2018
    Hi all,

    Before I dive into some timing tests of my own, I was curious if anyone already had some data, or could extrapolate based on the source code which scenario would be more efficient (or equal).

    1 RPC that sends 4 Vector3s
    4 NetworkVariable<Vector3>s

    And would the change in numbers be negligible? Like if there were 1000 Vector3s instead of 4.

    Also, would marking the RpcDelivery as Unreliable improve the performance in this case?

    Thanks for reading
  2. itisMarcii_


    Apr 5, 2022
    That depends completely for what you need it. NetworkVariable, unlike RPCMessages, can arrive on different ticks for each Client. So it could be arrive on Client X on Tick 10 while on Client Y it arrives on Tick 11.

    While RPCMessages can be more code and NetworkVariables have the OnStateChange, overall it depends on what you need. RPCMessages are better for sync, while NetworkVariables are convenient on some places.

    Unreliable and Reliable have one difference, while reliable secures your message to arrive, it also increases the Mbit/s. Since Reliable messages are at least send twice to secure that the package will arrive. Unreliable on the other hand sends the message only once, so if you lose that message on the traffic it will never arrive on the client.

    Overall its always better to wrap your date into one big message since it reduces the amount of headers. You can reduce your send data size by using bytes, shorts, ints ... cleverly.