-
Notifications
You must be signed in to change notification settings - Fork 1
Custom Room and Player properties
Laksh Gupta edited this page Feb 15, 2022
·
1 revision
Once a client is connected to the Photon Network they can create and access Custom Player properties
and once they join a room they can also access the Custom Room Properties
. Custom properties are useful to store values/variables that you need to sync over the network and are not attached to any object. For example the player Roles, Player Health etc.
Custom properties are stored as hash tables with string keys and values stored as bytes (maybe).
To access the hash table (Read Only) for custom properties use the following.
- For Custom Room properties
ExitGames.Client.Photon.Hashtable ht = PhotonNetwork.CurrentRoom.CustomProperties;
// depending on the type of value stored you want to cast the hash table value
int customVal = (int)ht["Custom Value"];
- For Custom Player properties
ExitGames.Client.Photon.Hashtable ht = PhotonNetwork.LocalPlayer.CustomProperties;
// depending on the type of value stored you want to cast the hash table value
int customVal = (int)ht["Custom Value"];
If you want to edit the properties you get the hash table in the same way shown above and then update the table using the SetCustomProperties()
method
- For Custom Room properties
ExitGames.Client.Photon.Hashtable ht = PhotonNetwork.CurrentRoom.CustomProperties;
// depending on the type of value stored you want to cast the hash table value
ht["Custom Value"] = "Hello World";
PhotonNetwork.CurrentRoom.SetCustomProperties(ht);
- For Custom Player properties
ExitGames.Client.Photon.Hashtable ht = PhotonNetwork.LocalPlayer.CustomProperties;
// depending on the type of value stored you want to cast the hash table value
ht["Custom Value"] = "Hello World";
PhotonNetwork.LocalPlayer.SetCustomProperties(ht);