Search Unity

Third Party Can't figure out how custom properties/PhotonSerializeView works

Discussion in 'Multiplayer' started by Avalin, Oct 17, 2018.

  1. Avalin

    Avalin

    Joined:
    Oct 12, 2018
    Posts:
    98
    Hey there!

    Here's my first problem. I want my character color to be sent to the server and distributed to other clients.
    Problem is all other clients return NULL when i try to retrieve other than LocalPlayers custom property, here's my code:


    Code (CSharp):
    1.     void SpawnPlayer()
    2.     {
    3.         playerGO = PhotonNetwork.Instantiate(Path.Combine("Prefabs/Player", "Player"), transform.position, Quaternion.identity).gameObject;
    4.         playerGO.GetComponent<PlayerProperties>().AssignRandomColor();
    5.  
    6.         Hashtable props = new Hashtable(){};
    7.         props.Add("colorR", playerGO.GetComponent<PlayerProperties>().playerColor.r);
    8.         props.Add("colorG", playerGO.GetComponent<PlayerProperties>().playerColor.g);
    9.         props.Add("colorB", playerGO.GetComponent<PlayerProperties>().playerColor.b);
    10.         PhotonNetwork.LocalPlayer.SetCustomProperties(props);
    11.  
    12.     }
    13.  
    14.     private void FindCustomization()
    15.     {
    16.  
    17.         foreach (Player player in PhotonNetwork.PlayerList)
    18.         {
    19.             Debug.Log("Color red in player "+ player.ActorNumber+": " +player.CustomProperties["colorR"]);
    20.            //RETURNS NULL FOR ALL OTHER THAN LOCAL PLAYER
    21.         }
    22.     }
    23.  
    24.  
    EDIT: So I found out there exist a method called "
    IPunCallbacks.OnPhotonPlayerPropertiesChanged ( object[] playerAndUpdatedProps )
    " .... In Pun v1.... What's the equivalent in Pun v2? Feels like a maze to figure this simple thing out



    So I also tried using PhotonSerializeView. This is for checking that a position made unavailable by Client2 also is made unavailable on Client1

    Code:
    Code (CSharp):
    1.     public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    2.     {
    3.         if (stream.IsWriting)
    4.         {
    5.             // We own this player: send the others our data
    6.             stream.SendNext(this.isAvailable);
    7.             Debug.Log("Sent stream packets");
    8.         }
    9.         else
    10.         {
    11.             // Network player, receive data
    12.             this.isAvailable = (bool)stream.ReceiveNext();
    13.             Debug.Log("Received stream packets");
    14.         }
    15.     }
    And YES I did implement the observable, and dragged the script to the photonView's observed component in the inspector. My Debug.Log tells me that the "Sent stream packets" gets called, but not the "Received stream packets". :/

    Oh yeah to elaborate on the exact problem: In most cases, client 2 registers that client 1's tile is unavailable as it should do. Client 1 however, doesn't register that client 2's tile is unavailable.
     
    Last edited: Oct 18, 2018