Having trouble getting player count on Fusion
The whole answer can be found below.
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).
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
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!
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