Syncing an entire component through network

Options
Hello there

So, I have this <Tile> component that i want to be kind of a network component. What i mean is that whenever someone changes some info in that script I want that info to be changed for all players.

I thought about trying something like this:
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
	{
		if (stream.isWriting)
		{
			// We own this tile: send info to the other tiles
			stream.SendNext(gridPosition);
			stream.SendNext(perioxi);
			stream.SendNext(NumberOfPlayersInArea);
			stream.SendNext(positions);
			stream.SendNext(taken);
			stream.SendNext(PlayersInArea);
			
			
			
		}
		else
		{
			// Network player, receive data
			gridPosition  = (Vector2)stream.ReceiveNext();
			perioxi  = (int)stream.ReceiveNext();
			NumberOfPlayersInArea  = (int)stream.ReceiveNext();
			positions  = (GameObject&#91;&#93;)stream.ReceiveNext();
			taken  = (bool&#91;&#93;)stream.ReceiveNext();
			PlayersInArea  = (GameObject&#91;&#93;)stream.ReceiveNext();
			
			
		}
	}
those are all the info that I want synced for everyone... However this way every player will try to send their info and eventually it will overlap (the Tile objects are not instantiated in any way, they are just local gameobjects that have the Tile script).

I also thought about setting all this stuff to the room's customProperties but I dont know how can I cast them back to their original types. Any help?

Comments

  • tester
    Options
    You could use: PhotonNetwork.isMasterClient
    http://doc-api.exitgames.com/en/pun/cur ... twork.html

    So only 1 client will be sending the info.
  • xjimdim
    Options
    you mean at the OnPhotonSerializeView ???
    something like:
    if (stream.isWriting)
          {
             // We own this tile: send info to the other tiles
             if(PhotonNetwork.isMasterClient){
             stream.SendNext(gridPosition);
             stream.SendNext(perioxi);
             stream.SendNext(NumberOfPlayersInArea);
             stream.SendNext(positions);
             stream.SendNext(taken);
             stream.SendNext(PlayersInArea);
              }
             
             
             
             
          }
    
  • tester
    Options
    Yes:
    // We own this tile: send info to the other tiles
    if (stream.isWriting && PhotonNetwork.isMasterClient){
    

    I Hope you can help me:
    viewtopic.php?f=17&t=6072
  • xjimdim
    Options
    hmm but what if those variables are changed by another player (not the masterclient)?
  • tester
    Options
    xjimdim wrote:
    hmm but what if those variables are changed by another player (not the masterclient)?

    As i can see your data is not from a Script right? If a player changes them, it could send and RPC to other players. So only 1 is sending the info. Like a chat.
    http://doc-api.exitgames.com/en/pun/cur ... 86f4036720
  • xjimdim
    Options
    the data are from a script. Yeah an RPC would be great if I could pass all this types of variables (like GameObject[] or something like that)
  • tester
    Options
    xjimdim wrote:
    the data are from a script. Yeah an RPC would be great if I could pass all this types of variables (like GameObject[] or something like that)

    ¿Why would you want to pass an entire gameobject?? That makes no sense :S
    The own RPC should be responsible to create the local GameObject if needed.
  • xjimdim
    Options
    I want to make a script that works locally work over the network for everyone and I use a list of certain gameobjects in the script... but I guess you are right, i will try to redesign it so as to make it more network friendly :P
  • tester
    Options
    xjimdim wrote:
    I want to make a script that works locally work over the network for everyone and I use a list of certain gameobjects in the script... but I guess you are right, i will try to redesign it so as to make it more network friendly :P
    Can't you setup them manually? Or they may change?

    Then you could send the object's name via RPC and set them by using GameObject.Find(NAME)