Syncing Entire Script of Ints & Floats

I have an entire set of player preferences ( floats, ints, strings ) I need synced across all clients!

The script is attached to a prefab, and when instantiated, they should all look different based on what they chose.
But for some reason only the earliest to connect to the network can see the other's color choices.

First client can see everyone's specially chosen colors. Second person can see everyone's but the first person- the first person looks just like them. Third person can see everyone's colors except first and second, and so on.

I tried to use stream.next with some of the floats but it did nothing.

Comments

  • It's not clear how you synchronize properties but may be better choice for you is player custom properties. Set them with PhotonNetwork.player.SetCustomProperties call on one side. And get them with player.customProperties on others. Where player is one from PhotonNetwork.playerList
  • I saw this thread viewtopic.php?f=17&t=1590

    and it looks like "SetCustomProperties" doesn't actually set properties. I'm also a bit confused on where exactly this code should be located, in the script full of properties or in a GameManager object that controls everything?

    And if you could include an example for me; Let's say I have three unique floats for color ( R G B ) and a bool that enables or disables a renderer or something. How would I set up those properties in a Hashtable, how would I use them, and how do I make sure all other players can see them.
  • What I'm asking for isn't too crazy is it? I can't find help for this anywhere. Photon's documentation is just not clear enough for me.
  • I agree with vadim, that using the player custom properties is probably your best bet. So when you set all these player preferences in your script, you'll want to do something like ...
    ExitGames.Client.Photon.Hashtable hashTable = new ExitGames.Client.Photon.Hashtable();
    hashTable.Add("PlayerColor", "blue");
    hashTable.Add("PlayerModelIndex", 0);
    etc..
    

    Once you have all your properties set in the hashtable, you call ...
    PhotonNetwork.SetPlayerCustomProperties(hashTable);
    

    Other players can then get that information by grabbing the PhotonPlayers customProperties. So something like this ...
    PhotonPlayer p = //get the PhotonPlayer;
    string color = (string)p.customProperties["PlayerColor"];
    int index = (int)p.customProperties["PlayerModelIndex"];
    etc...
    
  • Thank you so much for getting back to me! I'd lost all hope.

    I'm going to try it out right now.
  • It's giving me the same result. I set up the hashtable, call to set the player properties, and call other's information all in the same script " Network Character ". And it does the same thing it did before, with the earliest to join able to see differences, and the last to join sees everyone the same color.

    Where exactly am I going to want to call for other's information? I sync rotation and transformation in network character, but I decide who is controllable in Random Matchmaker ( via the Viking Tutorial ), so I'm not sure which script is appropriate for calling what. Thank you!
  • Please log setting custom properties and getting them along with player ids.
    Do you use properties of proper player when setting prefab color?
  • On the script that determines color, I use PlayerPrefs to get the data from another scene like this

    This is the "MyCharacterPreferences" script
    R = PlayerPrefs.GetFloat("R");
    G = PlayerPrefs.GetFloat("G");
    B = PlayerPrefs.GetFloat("B");
    

    In NetworkCharacter I get them like this
    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
        {
            if (stream.isWriting)
            {
    			//Character Values
    
    
                // We own this player: send the others our data
                stream.SendNext(transform.position);
                stream.SendNext(transform.rotation);
                myThirdPersonController myC = GetComponent<myThirdPersonController>();
                stream.SendNext((int)myC._characterState);
    			ExitGames.Client.Photon.Hashtable hashTable = new ExitGames.Client.Photon.Hashtable();
    			MyCharacterPreferences mCP = GetComponent<MyCharacterPreferences>();
    			float R = mCP.R; 
    			float B = mCP.B; 
    			float G = mCP.G; 
    			hashTable.Add ("R", R);
    			hashTable.Add ("B", B);
    			hashTable.Add ("G", G);
    			PhotonNetwork.SetPlayerCustomProperties(hashTable);
    			}
            else
            {
                // Network player, receive data
                this.correctPlayerPos = (Vector3)stream.ReceiveNext();
                this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
                myThirdPersonController myC = GetComponent<myThirdPersonController>();
    			myC._characterState = (CharacterState)stream.ReceiveNext();
    			foreach(PhotonPlayer player in PhotonNetwork.playerList)
    			{
    				float R = (float)player.customProperties["R"];
    				float G = (float)player.customProperties["G"];
    				float B = (float)player.customProperties["B"];
    			}
    
  • You do not need OnPhotonSerializeView to set player properties.
    Do it when colors are set or changed in any place in code.
    Read properties in OnPhotonPlayerConnected and OnPhotonPlayerPropertiesChanged handlers which fired when new player joins or existing player has changed properties. Or again, access them any place you like in code
  • I redid my color setting scripts, since using PlayerPrefs is NOT what I want to be using to set up customization.
    So players set their color in Scene 1. A script called "Savedata" on an object called "Dataobj" takes these values and keeps them for the remaining scenes.
    void Start()
    	{
    		DontDestroyOnLoad (target);
    	}
    	void Update()
    	{
    
    		CharacterPreferencesSetup charPrefSetup = MyCharacter.GetComponentInChildren <CharacterPreferencesSetup >();
    		R = charPrefSetup.R;
    		B = charPrefSetup.B;
    		G = charPrefSetup.G;
    
    	}
    

    In Scene 2, we connect to the Network and all Players connect and can see eachother. There is a new Script attached for showing the Character's color called "CharacterPreferences" instead of "CharacterPreferencesSetup" . This is where I decided to Set up the Character Properties.
    GameObject dataObj = GameObject.Find ("dataObject");
    		Savedata data = dataObj.GetComponent<Savedata>();
    		R = data.R;
    		G = data.G;
    		B = data.B;
    // Create hastable
    		ExitGames.Client.Photon.Hashtable hashTable = new ExitGames.Client.Photon.Hashtable();
    		hashTable.Add ("R", R);
    		hashTable.Add ("B", B);
    		hashTable.Add ("G", G);
    		PhotonNetwork.SetPlayerCustomProperties(hashTable);
    

    and in our Game Manager, it instantiates the character and applies the properties.
    void OnPhotonPlayerConnected()
    	{
    		
    		foreach(PhotonPlayer player in PhotonNetwork.playerList)
    		{
    			float R = (float)player.customProperties["R"];
    			float G = (float)player.customProperties["G"];
    			float B = (float)player.customProperties["B"];
    		}
    	}
    

    No errors, but my result is that player one sees everyone as (for example, red) and player two sees everyone as (for example, blue). I'm at where I started, and I'm wondering where to go from here?

    Sorry for asking so many questions, but thank you a million for the helping me!
  • Well, one thing to note I guess is that OnPhotonPlayerConnected only gets called when a remote client joins the room. So the last player to enter the room will never run that foreach loop. And where do you actually assign the colors? From the looks of that loop you cache the custom properties in floats and never actually use them anywhere?
  • Thank you for answering! I thought I was doomed.

    The values are used on the renderer.material to change the color of an item of clothing on the prefab characters within the "Character Preferences" script. And that's interesting to note that OnPhotonPlayerConnected doesn't run that loop. But you wouldn't reccommend using RPC methods or anything like that to send the color values to everyone connected within a room?
  • Sorry to bring this up again. I redid the way that I had my network set up to see if maybe that would fix this issue.

    I noticed this when I was reading through this thread viewtopic.php?f=17&t=1590
    dreamora wrote:
    The custom properties should broadcast but you need to tell them to do so when setting a property.
    Potentially the PUN layer doesn't do that (not sure, haven't checked the latest version. the one we use doesn't expose custom props at all) in which case the update is only sent from client to photon but not broadcasted to the room itself and the other clients which would result in what you see

    I've got the same results as the poster, there never seemed to be an answer to how they broadcasted the properties though. How does one go about doing that? Does it require OnPhotonSerializeView?
  • There is no way to control player custom properties broadcast.
    After you set them with PhotonNetwork.SetPlayerCustomProperties on one client, you can always access them via player.customProperties on every other client joined same room.