Compare the overhead between OnPhotonSerializeView and RPC

Hi, I would like to know the transfer overhead between using OnPhotonSerializeView and using RPC, in terms of the transfer volume and speed. For example:
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
	if (stream.isWriting)
		stream.SendNext(counter);
	else
		counter = (int)stream.ReceiveNext();
}

Compare to following:

In server:
	photonView.RPC("ReportCounter", PhotonTargets.OthersBuffered, counter);

In client:
	[RPC] void ReportCounter(int _counter)
	{
		counter = _counter;
	}

I want to minimise the total data transfer and keep the quality of speed. Which one is preferred? Why?

Comments

  • Serialize has the benefit that it can be delta compressed or (preferable) be sent as unreliable. It also gets aggregated in less messages if possible.
    It has the downside that it's called and sent often. If you don't put anything into the stream, the update will be skipped.

    If you wan to send "actions" infrequently, then RPC is the tool to use. It might not be aggregated or compressed but it's not double the size or anything.

    In general, minimize the use of strings and keep the rest of them short. Send less and only what you really need.
    Example: If you send position updates frequently and speed is a fixed value, then don't send speed in each update)


    We also have RaiseEvent which is independent of GameObjects and views. It has the least overhead and most options but it's also a bit complex to use maybe. On the other hand, you can send byte[] or other content any way you
  • So you meant RPC is "reliable"? Sorry I didn't deeply dig the document.

    I will also look at the RaiseEvent as you suggest. Thanks
  • Yes, if you call a method, we make sure that method IS being called on all clients. That needs to be reliable.
    RaiseEvent can be used to implement something similar to RPCs (in fact, RPCs use Events under the hood). You can do this reliable or unreliable, too.
  • Thanks x 1000