Having trouble getting player count on Fusion

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 Fusion.

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.

Having trouble getting player count on Fusion

Hedayk
2022-04-12 23:53:25

Anyone have ideas on what I'm doing wrong, or alternatives to getting a player count from a networked session?

int playerCount = Runner.SessionInfo.PlayerCount;

and

int maxCount = Runner.SessionInfo.MaxPlayers;

are both returning 0 for me.

This is coming from an object with a NetworkObject component attached to an object that has a script that is a NetworkBehaviour. No console errors. They are also only called after Spawned() is called.

Any help would be greatly appreciated!

Comments

ramonmelo
2022-04-21 10:09:48

Hi @Hedayk ,

Runner.SessionInfo.PlayerCount and Runner.SessionInfo.MaxPlayers are valid only for matchmaking when you are looking into sessions from a Lobby.

On the Server, you can get the current Player count like this NetworkRunner.ActivePlayers.Count().

--

Ramon Melo

Photon Fusion Team

Vector_Mike
2022-09-15 12:54:38

That doesn't compile, but this will new List<PlayerRef>(_runner.ActivePlayers).Count

Not as clean and efficient as I'd like. If there's a better way, do tell!

Luke_Sta
2022-09-15 13:00:48

Runner.ActivePlayers.Count();    

This does compile as long as you include:

using System.Linq;    

VVSRaySoyama
2022-12-22 02:15:49

Hello!

@ramonmelo

Could we update the wording on the documentation of "SessionInfo" under NetworkRunner?

Currently, it states that it returns information about the CURRENT session which is not always true.

Follow up question: Is there a way to get the Sessions MaxPlayer Count while already connected to a session?

Isaac_Augusto
2023-01-03 12:15:42

Hey,

To get the MaxPlayerCount, you could just store the value you're going to pass toStartGameArgs.


Isaac Augusto

Photon Fusion Team

Back to top