PutTeams. Last client playerlist empty

Options
Greetings.
1st scene: lobby when players get to see their names in a list. When players join room they're assigned a team using PunTeams (Controller has PunTeams attached). When room's playersCount reaches maxPlayers value then second scene is loaded.
2nd scene: also has PunTeam component attached to controller which is responsible for spawning players.Every client is ok but last – PunTeam list is empty on new scene load for the last client joined the room.

Team assignment:
public class PlayerListUIController : Photon.PunBehaviour
{
public override void OnJoinedRoom()
{
PhotonNetwork.player.SetTeam(PunTeams.PlayersPerTeam[PunTeams.Team.red].Count >= PunTeams.PlayersPerTeam[PunTeams.Team.blue].Count ? PunTeams.Team.blue : PunTeams.Team.red);
}

public override void OnPhotonPlayerConnected(PhotonPlayer otherPlayer)
{
if (PhotonNetwork.room.PlayerCount >= roomPlayerCount) {
PhotonNetwork.LoadLevel(roomName);
}
}
}

In 2nd scene, I check the player's team, and it returns blue, but if I check PunTeams list it's empty and has no players, this is true only for last client who joined the room and was loaded in a scene.

Answers

  • Hi @Madcode,

    when you load another scene, the PunTeams component gets destroyed. In the new scene a new PunTeams component is created which has default (empty) lists. Since PunTeams gets only updated, when a new client joins the room, an existing client leaves the room, a clients Custom Player Properties are changed or the local client calls OnJoinedRoom (which doesn't happen in your case) the lists will stay empty. To work around this behaviour, you can check the following two possibilities you have.

    The first one is to mark the PunTeams object as DontDestroyOnLoad. This way, the object 'survives' loading another scene and won't reset. You would have to remove the component from the second scene and destroy it when returning to the first scene.

    The other option is to call UpdateTeams() on the PunTeams component manually when the second scene is loaded. This might be the easier solution.