Unity Photon PUN - Get all players in the current game

Hi,

I am making a multiplayer game in which players are spawned in on level 1, they are supposed to finish a task, and when done they need to wait for all players to finish the task before everyone moves on to level 2.

For this I thought I’d save all instantiated players into a list when they are spawned, something like this:

[SerializeField] GameObject playerObject;
public List<GameObject> allPlayersInGame = new List<GameObject>();

private void SpawnPlayer()
    {
        GameObject _player = PhotonNetwork.Instantiate(playerObject.name, startPos.position, startRot.rotation);
        allPlayersInGame.Add(_player);
    }

However, when I print the length of the list in the update loop of my game controller it is always 1. I tried to print PhotonNetwork.PlayerList.Length which gives me 1 when I add first player and then correctly 2 when 2nd player joins.

What is the most simple way I can store all players (player objects) that joins the game and then access each of thems script later on?

How about PhotonNetwork.CurrentRoom.Players?

Does this list all the gameObjects associatede with the players? Because I have a bool in each player object script which is set to true when the player has made the task. And I need to check if all player script bools are set to true before moving on to next level.

No, this is a list of all the players in the current room. Maybe accessing the bools from the other script would help, and check it for all the players in the current room