Where do we call "PhotonNetwork.ConnectToRegion("cn");" when connecting to China's server?

I followed steps 1 and 2 on Photon's Region's webpage by getting my AppID unlocked and changing NameServerHost to "ns.photonengine.cn" in the "LoadBalancingClient.cs" file.

For the final steps, in which script do I call PhotonNetwork.ConnectToRegion("cn");? I'm able to still play my scene, but I get this long warning in my console:
JoinRandomRoom failed. Client is on MasterServer (must be Master Server for matchmaking) but not ready for operations (State: Joining). Wait for callback: OnJoinedLobby or OnConnectedToMaster.
UnityEngine.Debug:LogError(Object)

Photon.Pun.PhotonNetwork:JoinRandomRoom(Hashtable, Byte, MatchmakingMode, TypedLobby, String, String[]) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:1562)
Photon.Pun.PhotonNetwork:JoinRandomRoom() (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:1496)
Com.MyCompany.MyGame.Launcher:OnConnectedToMaster() (at Assets/My Project/Scripts/Launcher.cs:125)
Photon.Realtime.ConnectionCallbacksContainer:OnConnectedToMaster() (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:3408)
Photon.Realtime.LoadBalancingClient:OnOperationResponse(OperationResponse) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2161)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(StreamBuffer) (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PeerBase.cs:619)
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands() (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/EnetPeer.cs:550)
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands() (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PhotonPeer.cs:1504)
Photon.Pun.PhotonHandler:FixedUpdate() (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:116)

Best Answers

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited June 2019 Answer ✓
    Hi @mgzhangvr,

    Thank you for choosing Photon!

    PhotonNetwork.ConnectToRegion("cn") should be called when you want to connect to a region but we recommend that you set the region in the PhotonServerSettings' AppSettings, FixedRegion field to "cn" and call PhotonNetwork.ConnectUsingSettings() or do not change your code if you are already doing so.

    Connection method can be added to a MonoBehaviour's Awake or Start or OnEnable.
    It can also be called as a button action method or another UI callback.
    You just call it when you want to start connecting to Photon servers.

    Regarding the error log message.
    It has absolutely nothing to do with the previous question about PhotonNetwork.ConnectToRegion("cn").
    As the message itself states, you are calling JoinRandomRoom while the client state does not allow it because the client is currently "Joining" a room.
    JoinRandomRoom can be called only when the client is connected to MasterServer or joined to a lobby.
  • mgzhangvr
    mgzhangvr
    Answer ✓
    Your advice worked. No more red error messages, although my internet in China is super slow haha. Thank you!

Answers

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited June 2019 Answer ✓
    Hi @mgzhangvr,

    Thank you for choosing Photon!

    PhotonNetwork.ConnectToRegion("cn") should be called when you want to connect to a region but we recommend that you set the region in the PhotonServerSettings' AppSettings, FixedRegion field to "cn" and call PhotonNetwork.ConnectUsingSettings() or do not change your code if you are already doing so.

    Connection method can be added to a MonoBehaviour's Awake or Start or OnEnable.
    It can also be called as a button action method or another UI callback.
    You just call it when you want to start connecting to Photon servers.

    Regarding the error log message.
    It has absolutely nothing to do with the previous question about PhotonNetwork.ConnectToRegion("cn").
    As the message itself states, you are calling JoinRandomRoom while the client state does not allow it because the client is currently "Joining" a room.
    JoinRandomRoom can be called only when the client is connected to MasterServer or joined to a lobby.
  • mgzhangvr
    mgzhangvr
    Answer ✓
    Your advice worked. No more red error messages, although my internet in China is super slow haha. Thank you!