Question around the OnPhotonSerializeView

Options
Hey,

I know I post here a fair bit I just want to become as knowledgeable as I can with PUN. o:)

So I had a misunderstanding with how the OnPhotonSerializeView worked. I thought that isWriting was called when that instance is making a change, and the else was when someone else had written a change. After putting some debugs in I found that the isWriting gets called around 2 per second by the owner. So when player1 would take damage from player2 by modifying the value directly, a few moments later it would go back to the original value.
private void PhotonQuickSync< T >(PhotonStream stream, ref T syncItem)
{
    if (stream.IsWriting)
        stream.SendNext(syncItem);
    else
        syncItem = (T)stream.ReceiveNext();
}
A simple RPC gets the job done. But I'm wondering if the OnPhotonSerializeView can still be used? I quite like it, especially if I can create the above function and call a value to be synced in one line. Rather than creating the RPC function, then calling the RPC function. :)


Cheers.

Answers

  • GLucas
    Options
    For actions you generally want to use an RPC to cut down on what you would be syncing at your sync rate. So id advise that.

    However, if youre wanting to sync a health var, you would want the reactionary logic to be on the receiving player so that way when they get that reaction, they can set their local value and have that distributed to the stream readers. If you set the targets health locally without that other client knowing over the network, then youll run into a case as you noted where it changed for you momentarily, and when your stream reads their view its what their value is so it corrects.