Set/read network variable? (SetCustomProperties)

Hi, I am trying to set a custom variable (player gender). Then when a new player is detected I will read from this network variable and activate the correct player group in the prefab clone.

Can I set/get a variable with SetCustomProperties ? any example?
void FixedUpdate()
if (photonView.isMine)
//do nothing
} else {
//if their position is 0,0,0, move them to where they should be then..
//read the gender from custom properties before activation


  • Hi @Kekora,

    you can use PhotonNetwork.SetPlayerCustomProperties(Hashtable customProperties) to set the local player's custom properties. You can insert values to the hashtable by calling Add(...) function, e.g. customProperties.Add("gender", "m");.

    You can get the values by using PhotonNetwork.player.CustomProperties["gender"]; for the local player. If you want to have values from all player you can iterate through PhotonNetwork.playerList or PhotonNetwork.otherPlayers.
  • KekoraKekora
    edited March 2017
    thank you, I put
    using Hashtable = ExitGames.Client.Photon.Hashtable;
    to try and give me access to using the customProperties and the Hashtable but it does not like it.
    Is there something else I need to "use" or import for this?
  • KekoraKekora
    edited March 2017
    Edit: I think this works, I am yet to get it setting/reading from a remote player properly but it's a start.

    using PhotonHashTable = ExitGames.Client.Photon.Hashtable; //at the top private PhotonHashTable customProperties; //specify the hashtable PhotonNetwork.SetPlayerCustomProperties(customProperties); //in OnJoinedRoom() PhotonNetwork.player.customProperties.Add("race", tmp_race_float); //set it tmp_race = (float)PhotonNetwork.player.customProperties["race"]; //trying to read it back

  • I'm a bit stuck with this, when trying to read off the remote player's properties it says it does not exist? perhaps it was not published to the network in the first place?

    NullReferenceException: Object reference not set to an instance of an object
                        float tmp_race = 0.0f;
                        foreach (PhotonPlayer netPlayer in PhotonNetwork.playerList)
                            if ( == myDood_ownerName)
                                print("netplayername is " +;
                                tmp_race = (float)netPlayer.customProperties["race"]; //errors here
  • try:
    	tmp_race = (float)netPlayer.customProperties["race"]; 
  • that does remove the error because the property will only attempt to be accessed if it is set.

    but the property is not being set. am I setting it wrongly?
  • OneManArmyOneManArmy ✭✭✭
    edited March 2017
    PhotonHashTable setRace = new PhotonHashTable();
    setRace.Add("race", tmp_race_float);
    PhotonNetwork.player.SetCustomProperties(setRace, null, false); 
  • thank you! that is the good way of setting it.
    is working now.

  • Can I have to custom properties of remote players?
    example: Custom property client A is : "Client A" and Custom Property client B is "Client B". How can I show "Client B" to client A?
Sign In or Register to comment.