This document is about: PUN 2
SWITCH TO

PUN Classic (v1), PUN 2 and Bolt are in maintenance mode. PUN 2 will support Unity 2019 to 2022, but no new features will be added. Of course all your PUN & Bolt projects will continue to work and run with the known performance in the future. For any upcoming or new projects: please switch to Photon Fusion or Quantum.

App and Lobby Stats

Photon servers can broadcast application and lobby statistics to clients.
You can make use of this data to implement a complex custom matchmaking system.
You can also brag about these statistics in your game to show how popular it is. :]

Application Statistics

When connected to a Photon master server, a Photon client receives applications statistics.
Regardless of whether the client is joined to a lobby or not, it will receive AppStats events.

The applications statistics are:

  • Number of live rooms:

    C#

    PhotonNetwork.CountOfRooms
    
  • Number of players not joined to rooms:

    C#

    PhotonNetwork.CountOfPlayersOnMaster
    
  • Number of players inside rooms:

    C#

    PhotonNetwork.CountOfPlayersInRooms
    
  • Total number of connected players:

    C#

    PhotonNetwork.CountOfPlayers
    

    AppStats event is sent to client every five seconds.

Lobby Statistics

Lobby statistics can be useful if a game uses multiple lobbies and you want to show the activity.
Lobby statistics are per region.

Per typed lobby (name + type) you can get information about:

  • Number of live rooms
  • Total number of players joined to the lobby or joined to the lobby's rooms

Automatically Get Lobby Statistics

Lobby statistics events are sent as soon as the client is authenticated to a master server.
Then they are sent every minute.
Lobby statistics events are disabled by default.

In PhotonServerSettings, check "Enable Lobby Stats" to get lobby statistics from the server.

If you want to do it from code before connecting:
PhotonNetwork.PhotonServerSettings.AppSettings.EnableLobbySatistics = true;
This works when you connect using PhotonNetwork.ConnectUsingSettings() as that's the only connect method that actually makes use of the ScriptableObject ServerSettings.
If you need to use another connect method, then you should use PhotonNetwork.NetworkingClient.EnableLobbyStatistics = true; before connecting.

Get the statistics from the ILobbyCallbacks.OnLobbyStatisticsUpdate callback which could be useful to update your UI.

Back to top