OnPhotonSerializeView

Hi, i understand what RPC's do, but i dont understand from what is written in the photon cloud overview exactly what OnPhotonSerializeView does. could some one dumb it down a bit for me, or possibly explain why it would be used over an RPC?

Comments

  • It does the same thing OnSerializeView does in Unity, so you can alternatively look at its documentation

    It allows you to fill data of your choice into a stream / read from the stream to send through any kind of data. The difference to RPC is that its automatic at periodic intervals.

    you can define it to be unreliable or reliable delta compressed
  • dreamora wrote:
    It does the same thing OnSerializeView does in Unity, so you can alternatively look at its documentation

    It allows you to fill data of your choice into a stream / read from the stream to send through any kind of data. The difference to RPC is that its automatic at periodic intervals.

    you can define it to be unreliable or reliable delta compressed

    Do I need to use OnSerializeView or can I just use my own timer and RPCs (or is that too slow)?

    Also, what is the frequency (messages per second).

    Thanks!

    -Carmine
  • You won't gain anything by replacing OnSerialize with RPCs. OnSerialize is much leaner and if you call RPCs in intervals, they just behave like OnSerialize with more traffic.
    RPCs are for "events" that are less frequently or irregularly send.

    The frequency is defined by PhotonNetwork.sendRate (20x /sec) and PhotonNetwork.sendRateOnSerialize (10x /sec).
  • Tobias wrote:
    You won't gain anything by replacing OnSerialize with RPCs. OnSerialize is much leaner and if you call RPCs in intervals, they just behave like OnSerialize with more traffic.
    RPCs are for "events" that are less frequently or irregularly send.

    The frequency is defined by PhotonNetwork.sendRate (20x /sec) and PhotonNetwork.sendRateOnSerialize (10x /sec).

    Tobias... is there a way to switch the view.... or who is doing the serializing?

    For instance.. instead of using the .IsMine in the serialize... can I do something like

    if (IAmThePiolot)
    {
    send
    } else {
    read
    }

    Thanks!
  • I think you will have to take a closer look at ownership to make this work. The problem is that the framework that calls OnSerialize will also decide (by isMine) if the stream is read-only or write-only.
    Also, all clients need the same idea of who is in charge of any object, so they each read except the one who owns the object.
    It's sadly not as simple as overriding it in OnSerialize.
    A property might sync the owner for an object but this can changed by everyone and you have to make sure you don't run into race conditions where 2 clients take control at the same time and send that to the server.