[PUN2] PhotonTeamManager not accurately reflecting player count


I am currently trying to implement teams in my game and have run into a few issues regarding the provided PhotonTeamManager. Currently, upon entry to my room, I have players sit in a waiting lobby where they are randomly assigned to the red or blue teams using
. Then afterward, during gameplay, I display the number of players left on each team using the following function:
public override int playersLeft(string team)
        int teamCount = PhotonTeamsManager.Instance.GetTeamMembersCount(team);
        if (team == TeamAssignment.RED)
            return Mathf.Abs(teamCount - redDead);
        else if (team == TeamAssignment.BLUE)
            return Mathf.Abs(teamCount - blueDead);
        return -1; //Invalid team


However, even though at least one person is connected to the game, I have noticed that the teamCount variable always returns 0. Is this just because the teamCount variable doesn't include the current player? Or did I set up the team system wrong (JoinTeam is returning true, and the commented function correctly returns the team)?


  • Same here! The counter only works in OnPlayerJoinedTeam method. I have zero in the next code (when I am assigning the team to the player):

    PhotonTeam[] availableTeams = mPhotonTeamsManager.GetAvailableTeams();
    PhotonTeam teamBlue = availableTeams[0];
    PhotonTeam teamRed = availableTeams[1];
    int playersCountBlue = mPhotonTeamsManager.GetTeamMembersCount(teamBlue);
    int playersCountRed = mPhotonTeamsManager.GetTeamMembersCount(teamRed);

    Can someone help us please? Thanks in advance.
  • Hi @Gwaaf,

    Thank you for choosing Photon and sorry for the delay on this one!

    Not sure when do you call the overriden "playersLeft" method but the client should be in the room when you use team manager methods.

    Hi @pamplins,

    Thank you for choosing Photon!

    This is by design, all teams methods work only while inside/joined to a room.
    The only exception is that you could assign and cache the team for the local player before joining probably.
  • Hi! Finally I have saved the team in the data when I instantiate the player and then accessing itm I have been able to do what I wanted. In the inspector, I have the players in the right team. Thanks for the help!
Sign In or Register to comment.