0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Unity PhotonUnityNetwork2(PUN2) OnJoinedRoomが呼ばれない件について

Posted at

Unity PhotonUnityNetwork2(PUN2) OnJoinedRoomが呼ばれない

あるときPUN2が正常動作しないことに気づきました。
マスターサーバーに接続が成功すると呼ばれるコールバックメソッドのOnConnectedToMasterは正常に呼ばれています。

   public override void OnConnectedToMaster()
    {
        Debug.Log("PUN2 OnConnectedToMaster");
        PhotonNetwork.JoinOrCreateRoom("Room", new RoomOptions(), TypedLobby.Default);
    }

ですが、ルームへの接続が成功した時に呼ばれるコールバックメソッドのOnJoinedRoomが呼ばれないことに気づきました。

public override void OnJoinedRoom()
    {
        //これが呼ばれない
        Debug.Log("PUN2 OnJoinedRoom");
    }

PUN2のログの確認

何はともあれ、ログを確認してみます。
PUN2の詳細なログを出すには、
PhotonServerSettings.assetをUnityで開いてインスペクターのSupportLoggerにチェックを入れます。

以下のディレクトリパスにPhotonServerSettings.assetがあります。
Assets/Photon/PhotonUnityNetworking/Resources/PhotonServerSettings.asset

スクリーンショット 2023-03-08 15.35.52.png

エラーの確認

私の場合は以下のエラーが出ていました。
OnJoinRoomFailed Failed to get server instance.

解決

先ほどのPhotonServerSettings.assetを開いて「Dev Region」に「us」を追加したら解決しました。
恐らく、jpの方のサーバーが何かしらのトラブルが起きていて接続できなかったのだろうと推測しています。
デバッグ環境であれば問題ないですが、リリース時には必ず元の設定に戻してください。

Dev Region
jp,us

スクリーンショット 2023-03-08 15.42.32.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?