Sending data from master client to build scene

Hello everyone,

I have been using photon for a couple of days and I am not sure on how to send data to the other clients before the beginning of the game. This is what I need to do:

1) the clients join the room.
2) the master client generates a random seed for the creation of the level and sends it to the other clients, then it builds the level.
3) the other clients receive the seed from the client and build the same level.
4) the game starts.

What is the best way to do something like that?

Thanks!

Comments

  • For building the level my first thought would be to use PhotonNetwork.InstantiateSceneObject. It will persist throughout the game and can be seen by everyone connected immediately. That may by pass having to signal the other connected clients.

    In terms of signalling that the client, if you needed, a photonView.RPC call can do that.
  • Seeds and initialization for the game round can be done by Custom Properties. Use Room.SetCustomProperties(). There is a callback when they are set, so you can react to that even if someone joins the game before they are setup.
    Then every player sets a Custom Property via PhotonPlayer.SetCustomProperties() when it's ready. Check those in the Master Client and you know when you can start the game.
  • Thanks for the answers! I'll give it a try :D
  • I am having a problem using the hashtable method to set the seed for the players. Here's a code snippet:
    // Use this for initialization
    	void Start () {
    		Init ();
    	}
    
    	void Init (){
    
    		hashtable = new PhotonHashtable();
    
    		if (PhotonNetwork.isMasterClient){
    			CreateRandomSeed();
    			hashtable.Add("seed",seed);
    			PhotonNetwork.room.SetCustomProperties(hashtable);
    		}
    		else{
    			PhotonHashtable table =  PhotonNetwork.room.customProperties;
    			seed = (int)table["seed"];
    		}
    
    		CreateTrack(seed);
    		CreateCharacter();		
    	}
    

    when the first player establishes the connection and creates a room, the seed is generated and set as a property in the hashtable. When the second player connects, the value of his seed should be taken from the hashtable, but for some reason this doesn't work the first time; a null exception is raised and the hashtable is empty. However, if a third player tries to connect, he is able to get the seed correctly. Is there a reason for this behaviour?
  • Hi,

    Client should be connected to the room before updating or getting room properties or checking PhotonNetwork.isMasterClient
    Try move code to OnJoinedRoom handler.
    Also better init seed and put it in room properties when creating room, not when master joins.
  • I moved the code and it worked ! Thanks for your help!