Syncing object's color to all players?

I'm trying to sync an object's render.material.color, to all other player's basically.

I have a basic understanding of Unity and Photon, and I've tried sending an RPC to change the color, but the problem is, when another player joins the room, they can't see the color change, and its default for them.

I've heard of the Stream.Sendnext etc, etc. But I'm not sure if this works for things other then Position, and Rotation. I don't know how I'd set it up to Stream an objects color.

I need to know what's the best way of doing something like this, and honestly this goes for other syncing issues aswell, such as visual stuff, on each player.

I would truely love some help on this, I don't quite need to post code, as its not really code related for me, I actually need to know how.

Comments

  • Yes, the problem with RPCs is that joining players won't notice the change. You could fix that by buffering the RPC, which basically means new players get the buffered events when they join (after properties and before anything else). Problem with that: They will get each color change, not only the current state.

    Depending on how often color changes you can:
    a) Sync it as custom value which you provide in OnPhotonSerializeView. This is good if color can change often (5+ times a second)
    b) Use a custom player property to store the current color per player. This is good if color changes rarely (by user input).
    PhotonNetwork.player.SetCustomProperties can be used to set it per client. You only have to check if it's known and apply it then.
  • Hmm, could you show me an example? I'm still kind of learning, and don't quite understand.
  • I just noticed that I don't have a good example for that really but it's easy enough to do.
    Find PhotonPlayer.SetCustomProperties. Read the text that describes it.

    You can use it to set key-value pairs (a hashtable) as "properties".
    When you set something, the others will be able to read it as PhotonNetwork.players.CustomProperties. This is a hashtable, too. Use some key like "color" and you should be fine.