Having trouble getting player count on Fusion

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!

Answers

  • 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

  • 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;
    
  • 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
    edited January 2023

    Hey,

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

    -----

    Isaac Augusto

    Photon Fusion Team