Cannot get another player to join a room when the game has started.

Options
So I followed Info Gamer's tutorial on how to make a Lobby and a Room. The LobbyGO would allow players to create a room or display all rooms available, while the RoomGO will display all players in said room.
A few months ago, this was working fine, but ever since I updated PUN, there is a problem. I can get a player to join a room and start game. I can get multiple players into a room and then start a game. But I cannot get a player to start a game and then have other players join game. The error unity gives me when I am trying to access an ongoing game, is that a gameobject I am trying to access has been destroyed.

Below is my OnJoinRoom. I appreciate any help given. Thank you.

public override void OnJoinedRoom()
{
base.OnJoinedRoom();
Debug.Log("We are in a new room");

lobbyGO.SetActive(false); //error: gameobject has been destroyed.
roomGO.SetActive(true);

if(PhotonNetwork.IsMasterClient)
{
startButton.SetActive(true);
}

ClearPlayerListings();
ListPlayers();

photonPlayers = PhotonNetwork.PlayerList;
playersInRoom = photonPlayers.Length;
myNumberInRoom = playersInRoom;

// for delay start only
if (MultiplayerSetting.multiplayerSetting.delayStart)
{
Debug.Log("Display players in room out of max players possible (" + playersInRoom + ":" + MultiplayerSetting.multiplayerSetting.maxPlayers + ")");
if (playersInRoom > 1)
{
readyToCount = true;
}
if (playersInRoom == MultiplayerSetting.multiplayerSetting.maxPlayers)
{
readyToStart = true;
if (PhotonNetwork.IsMasterClient)
return;
PhotonNetwork.CurrentRoom.IsOpen = false;
}
}
}

Answers

  • Bassem
    Options
    i think by doing this
    PhotonNetwork.CurrentRoom.IsOpen = false;
    
    you block the access to the room, maybe if you adjust the maxPlayers it will work.
  • Sorry if pasting the code makes it harder to read, but the room only closes when playersInRoom == MultiplayerSetting.multiplayerSetting.maxPlayers. And that half of the code could be ignored. Really it should just look like this:
    public override void OnJoinedRoom()
        {
         //sets player data when we join the room
            base.OnJoinedRoom();
            Debug.Log("We are in a new room");
    
            lobbyGO.SetActive(false);
            roomGO.SetActive(true);
            if(PhotonNetwork.IsMasterClient)
            {
                startButton.SetActive(true);
                muteAllToggle.SetActive(true);
                removeButton.SetActive(true);
            }
    
            ClearPlayerListings();
            ListPlayers();
    
            photonPlayers = PhotonNetwork.PlayerList;
            playersInRoom = photonPlayers.Length;
            myNumberInRoom = playersInRoom;
    }
    
  • Tobias
    Options
    The error unity gives me when I am trying to access an ongoing game, is that a gameobject I am trying to access has been destroyed.

    You have to figure out which object this targets and why it's gone.
    With the info we got, we can not help with that and it isn't a bug in Photon as such, so I can only point towards "the usual" debugging workflows.
    Maybe you switch scenes? Then objects are usually destroyed by Unity (unless you load additive).
  • Thank you for the response.
    As I stated, this code worked before I updated photon, so I am wondering if the update changed how JoinRoom works. I am looking through the documentation and the provided demos right now to help me with my problem. From my understanding, it goes from lobby->room->game. Is there a demo where I can join a room of an ongoing game? I looked through most of the demos and maybe I missed something, but I can only find games, such as asteroid, where you can only join a room when the host is in the room.