It takes time when I re-enter the same game-room

I am developing a Unity game app with PUN.
My problem is... at first, two players are OK with getting into the game. However, when one of them gets out (using PhotonNetwork.LeaveRoom()) and tries to re-enter the same game-room (using PhotonNetwork.JoinRoom(room name)), it takes a while. And it takes longer as you try again. Sometimes it doesn't even move at all.
Please help me. The source code about entering the game_room is here...
I am using Unity 2017.3.1f1. Thanks.
-------------------------------------------------------------
public void PlayGame() {
    foreach(RoomInfo ri in PhotonNetwork.GetRoomList()) {
        if (ri.PlayerCount < ri.MaxPlayers) {
            PhotonNetwork.JoinRoom(ri.Name);
            break;
        }
    }
}

void OnJoinedRoom() {
    ...
    StartCoroutine(Battle_Scene());
}

IEnumerator LoadBattleField() {
    PhotonNetwork.isMessageQueueRunning = false;
    AsyncOperation ao = SceneManager.LoadSceneAsync("Battle_Scene");
    yield return ao;
}

Comments

  • I think my explanation is not good enough to understand my situation. Here is more details ...
    Users do not have a problem with getting into the same game room again. It means it is OK in Start().
    I put texts everywhere and I got the text at the end of Start() in no time.
    And then it gets very slow. Looks like it stuck in something after Start).
    Like I said, it is OK at first. It happens when I try to get back in the same room using the same codes above.
    Can anyone help me? I am so desperate...
  • Hi @mhhk88,

    when you create a room, do you set a value larger than 0 for the PlayerTtl value from the RoomOptions? In this case, you can use PhotonNetwork.ReJoinRoom("Room Name"); to re-enter the game. If you want to, you can check if this approach is not affected by the scenario you have described.

    If you want to continue using your approach or the above one is not working either, please check if you have a lot of network traffic for example by receiving a lot of buffered messages. But I guess this is not a problem since OnJoinedRoom has already been called.

    Looks like it stuck in something after Start).


    You can add a Debug.Log call to the Update function which prints Time.time to the console. Having this you can check if there is an increased amount of time in between Update calls.

    Can you confirm that you are enabling the Message Queue again? It is disabled in the Coroutine but not enabled again, at least not in the code snippet you provided.
  • @Simon I did not set a value to PlayerTtl. I just set 10 to maxplayers in the RoomOption.
    And I enabled the PhotonNetwork.isMessageQueueRunning again in a script (Awake()) of Battle_Scene.
    As you suggest, I will add Debug.Log to every line of Update() and see what's happening.
    Obviously this is not supposed to happen, right?
  • I will add Debug.Log to every line of Update() and see what's happening.


    You don't have to do this for each line within an Update() function. It's enough having this once at the beginning of an Update() function of your choice. Then compare one of the Time.time logs with the next one and see, if there is something requiring a lot of processing time. If you are familiar with the Unity Profiler, you can also have a look there and see if this gives some more insights.

    Obviously this is not supposed to happen, right?


    You are right.
  • mhhk88mhhk88
    edited May 9
    @Simon I tried your suggestion. I put 'print("Timer : " + (Time.time - gameTimer));' at the beginning of Update().
    And it printed out only 1-2 times, which means it ran for only 1-2 frames in Update(). And it stuck. There is no something special in Update().
    Like I said, it happens when I get out of a game-room and get back in the same game-room.
    I left the room using 'PhotonNetwork.LeaveRoom();'. That's all I did when I left the game-room.
    Any other suggestions that I may need to try? Any callbacks that I miss or do something with?
  • Any callbacks that I miss or do something with?


    OnLeftRoom is the only callback which gets called when a client has left the room. If you have enabled the autoJoinLobby option, OnJoinedLobby will be called afterwards, because the client automatically joins the lobby again.

    Does this happen, too, if you try to add it to a new project? Can you possibly create a repro case? Which PUN version do you use?
  • I don't mention 'autoJoinLobby' in my codes, but OnJoinedLobby is called.
    I'm not sure what 'Can you possibly create a repro case?' exactly means.
    I think PUN version is 1.84. Because the change log in the PUN folder and PhotonNetwork-Documentation
    says so. Where else can I find my PUN version?
    Anyway, thanks for your time :)
  • I'm not sure what 'Can you possibly create a repro case?' exactly means.


    I'm asking for a project, where it is possible to reproduce the error, so that I can have a direct look at it. However I'm not asking for the entire project, but for another (new) project which includes the core files from PUN and the custom scripts, which are leading to this error. It might be also enough to just paste the code here which leads to the error, if it is only one class for example.

    I think PUN version is 1.84. Because the change log in the PUN folder and PhotonNetwork-Documentation says so. Where else can I find my PUN version?


    The version number in the changelog is already correct. Another location is in the PhotonNetwork class, it is called versionPUN. Since 1.84 is almost a year old, you can try updating PUN to the latest version to see if this already solves the problem. If there is any reason why you can't update, please let me know.
  • Using versionPUN, it tells my PUN version is 1.85. The latest PUN version is 1.9, right? I will try updating to it. If I still have the same problem after upgrading PUN, I will try to make a simple project with the same error. I'm not sure I can make it. But if I do, I will send it to you, if you don't mind.
    Thanks for your help.
Sign In or Register to comment.