Sync script variables to all players

Hello guys,

I have a script with dictionaries (Transform, Bool) to keep track of spawnposition and see if they're occupied or not. I put this on a scene object with a photonview observing it, but it doesn't share the data across the network.

How can I do this? I want the dictionary to be synced to all players, and each play can set the values of the dictionary to 'true' or 'false', in order to let other people know and "read" to see if they can spawn there.

Thanks!

Comments

  • Hi,

    Object fields are not synchronized automatically. You need to set up synchronization via RPC or 'OnPhotonSerializeView' handler.

    You may want to use room custom properties instead of PhotonView object to share spawn positions. Custom properties are dictionary which updated automatically across network each time any client changes it:
    set: PhotonNetwork.room.SetCustomProperties(ExitGames.Client.Photon.Hashtable with keys/values to update)
    get: PhotonNetwork.room.customProperties[key]

  • Thanks Vadim,

    Using the room's custom properties looks like the best approach. Too bad there's no such thing to sync a script object :neutral: