Accessing different players properties
I'm working on a "pre-game" feature where when a player joins a room it will bring up UI that shows the players stats on his account currently being saved with playfab statistics so public things such as overall "wins", "rating". Im using customplayerproperties to assign these values when each player joins a room, and then im using PhotonNetwork.LocalPlayer to put up all of his customplayerproperties related to overall stats. Now my question is what would be the best practice to show the other players customplayerproperties on the UI? Or how to access each players customplayerproperties separately. Its a 1v1 game so I got the local player working just not the other one who joins. Sorry if that wasn't articulated properly but i tried my best without screenshots. I can post screenshots if anyone needs a better understanding.
0
Best Answer
-
Hi @LucaBrasi,
Thank you for choosing Photon!
Actor properties are accessible only when joined to rooms.
Also, actor properties are per room and are not global or shared/persisted across rooms.
The local client's actor properties are an exception as they are cached locally, can be set before joining rooms and may be reused.
To access the actor properties for the remote players when joined to rooms, the idea is to test ifplayer.IsLocal
Player[] allPlayers = PhotonNetwork.PlayerList; for (int i = 0; i < allPlayers.Length; i++) { if (!allPlayers[i].IsLocal) { } }
Or:Player[] remotePlayers = PhotonNetwork.PlayerListOthers; for (int i = 0; i < remotePlayers.Length; i++) { }
Or easier since it's a 1v1:Player remotePlayer = PhotonNetwork.PlayerListOthers[0];
Or:Player remotePlayer = PhotonNetwork.LocalPlayer.GetNext();
Then get the property or properties:if (remotePlayer != null) { object customPropValue = remotePlayer.CustomProperties[customPropKey]; }
Actor properties changes have a callback:IInRoomCallbacks.OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps)
5
Answers
-
Hi @LucaBrasi,
Thank you for choosing Photon!
Actor properties are accessible only when joined to rooms.
Also, actor properties are per room and are not global or shared/persisted across rooms.
The local client's actor properties are an exception as they are cached locally, can be set before joining rooms and may be reused.
To access the actor properties for the remote players when joined to rooms, the idea is to test ifplayer.IsLocal
Player[] allPlayers = PhotonNetwork.PlayerList; for (int i = 0; i < allPlayers.Length; i++) { if (!allPlayers[i].IsLocal) { } }
Or:Player[] remotePlayers = PhotonNetwork.PlayerListOthers; for (int i = 0; i < remotePlayers.Length; i++) { }
Or easier since it's a 1v1:Player remotePlayer = PhotonNetwork.PlayerListOthers[0];
Or:Player remotePlayer = PhotonNetwork.LocalPlayer.GetNext();
Then get the property or properties:if (remotePlayer != null) { object customPropValue = remotePlayer.CustomProperties[customPropKey]; }
Actor properties changes have a callback:IInRoomCallbacks.OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps)
5