Using photon (how to synchronize) with other types

Using supported types I've already learned.
And unsupported types you Serialize / Deserialize.
But how do you set these values in my components?
In my current project, there is dynamic ground.
The sprite on the ground changes.
How do I send via RPC with the command to change the sprite?
Or the same thing by OnPhotonSerializeView?
How to sync a collider?
Excuse me, I'm a beginner ... But I can do some things already
I tried the following way:

private Sprite s;

private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
if (stream.isWriting) //Local player - send data
else //Remote player - receive data
s = (Sprite) ByteArrayToObject((byte[])stream.ReceiveNext());
if (photonView.isMine)
// Destroys the ground by applying the contact areas of the circle collider to transparent pixels and applies the
//change in texture.
GetComponent().sprite = s;

Or with RPC

when to destroy the texture and, apply, get the byte texture []...
And call RPC with a byte parameter []...
... photonView.RPC("change", PhotonTargets.All, spriteData);

There in the RPC

private void change(byte[] b ){
GetComponent().sprite = (Sprite) ByteArrayToObject( b );

Excuse me if the code is messy.
I do not know what else to do, I'm lost in that part.
I was able to synchronize the position and rotation.
With only this, I am already happy > _ <


  • edited May 2018
    Hi @dashart,

    if the functions ObjectToByteArray and ByteArrayToObject are working properly, it should already work, because Photon can (de-)-serialize those types (byte[]). Means that there is no need to use Custom Types for byte arrays. However sending the 'entire' image is not a good solution at all, because it would create a lot of network traffic and you will possibly have disconnects from the server which might disconnect certain clients who are sending too much data.

    If you are just using images that are already part of the project, it would be easier to just synchronize the name (or some kind of ID) of the active image with the other clients, so that they can apply the correct image to the object. Therefore using a RPC seems to be the best option.
Sign In or Register to comment.