How many players are in a scene?

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

How many players are in a scene?

SebGM2018
2018-11-15 03:39:20

do you know how can I get the number of players in a specific scene? I'm using Unity Photon's PUN 2, so, almost anything of PUN 1 won't work. Thanks.

Comments

[Deleted User]
2018-11-15 09:40:33

Hi @SebGM2018,

if you use PhotonNetwork.AutomaticallySyncScene, the number of clients in the scene is most likely the same as the number of clients in the room, which you can get by using PhotonNetwork.CurrentRoom.PlayerCount.

If you don't use AutomaticallySyncScene and have clients loaded different scenes, the clients would have to publish the name of the scene they currently have loaded. This can be easily done by using the Custom Player Properties. Whenever a client has finished loading a scene, he can update his Custom Player Properties with the name of the current scene. These properties are automatically synchronized across each client in the same room. By iterating through the PhotonNetwork.PlayerList each client can check, which other client has loaded a certain scene.

Back to top