[PUN2] how do I know if I'm connected to the gameserver or masterserver

Options

the reason I ask is that I get the following error:

Operation FindFriends (222) not allowed on current server (GameServer)

so I just want to check that I'm not connected to the gameserver to prevent this error. I did google but couldn't seem to find the answer.

any advice appreciated. thanks

Answers

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options

    Hi @hellohallo,

    In general, when you are joined to a room you are connected to the GameServer.

    Otherwise, if you are connected you are on the MasterServer.

    So I would use PhotonNetwork.InRoom or PhotonNetwork.IsConnectedAndReady.

    Otherwise you could also check values of PhotonNetwork.Server or PhotonNetwork.NetworkClientState.

  • hellohallo
    edited February 2022
    Options

    So if PhotonNetwork.InRoom is true it means we are definitely connected to a GameServer? If yes then I'll use that for now.

    I tried PhotonNetwork.NetworkClientState but it seems a few of those involve being connected to a gameserver, and not sure of the exhaustive list. For example when I was PhotonNetwork.Joined I got the error when trying to find friends, but there are also states like PhotonNetwork.ConnectedToGameServer. So I assume at least both of those involve being connected to a gameserver, and possibly other states too, so there isn't really just 1 state we can check on.