Search Unity

Third Party PHOTON: JoinLobby() PROBLEMS....

Discussion in 'Multiplayer' started by Peteroid69, Mar 31, 2022.

  1. Peteroid69

    Peteroid69

    Joined:
    Nov 11, 2018
    Posts:
    36
    i do the following using PHOTON:
    .
    in my first scene which just shows a title screen image... i connect to the master server... which fires the callback OnConnectedToMaster()... where i call JoinLobby().... which fires the callback OnJoinedLobby()... so so far so good...
    .
    i then load a new scene with SceneManager.LoadScene("scene name 1")... and then later to another scene also via SceneManager.LoadScene("scene name 2")... this last scene is where i use the callback OnRoomListUpdate()... which seems to be dependent on being in the Lobby...
    .
    but OnRoomListUpdate() never fires....as if i am no longer in the Lobby...
    .
    now... if i move the JoinLobby() to the last scene which uses OnRoomListUpdate()... it then DOES call OnRoomListUpdate()... BUT.... this every-once-in-a-while never fires OnJoinedLobby().. so once again i seem to not be in the Lobby...
    .
    so.... does going to a new scene cause the Lobby to be left... possibly because i use SceneManager.LoadScene instead of PhotonNetwork.LoadLevel()?
    .
    there does not seem to be a OnJoinLobbyFailed() callback...
    .
    so what am i doing wrong... and how does one RELIABLY enter a Lobby?
    .
     
    Last edited: Mar 31, 2022
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    Make sure the object / script that registered for the callbacks, is still around. When you load scenes, Unity destroys the objects that belonged to the previous scene and this may affect the code that should get callbacks.
    Each scene can register other scripts to get callbacks. Just make sure some are listening.
    If JoinLobby does not lead to OnJoinedLobby, the client may have disconnected or you did something else to leave the Master Server (e.g. create room, etc).
     
  3. Peteroid69

    Peteroid69

    Joined:
    Nov 11, 2018
    Posts:
    36
    .
    Thanks!... i think this is the problem... i do destroy the object that makes the JoinLobby() call and has OnJoinedLobby()... and your cool explanation tells me why future scenes are no longer in the Lobby... so what i will do is create an object that calls JoinLobby() and pass it to future scenes (i.e. don't destroy it) to maintain being in the Lobby...
    .
    thanks again!
     
  4. Peteroid69

    Peteroid69

    Joined:
    Nov 11, 2018
    Posts:
    36
    oh yeah... one more thing... i never even knew about REGISTERING the class that takes the callbacks until your post above.. NO tutorials i followed even mentioned it... and a lot seems to work even if you don't register...
    .
    and it took me a bit to figure out HOW to register classes for PHOTON PUN2 callbacks... but i finally found:
    .
    PhotonNetwork.AddCallbackTarget(this) and PhotonNetwork.RemoveCallbackTarget(this)
    .
    one problem with learning any system for the first time is some of the time you don't even know about the existence of a feature .. it is like you already have to know the system to know what you need to know about the system... LOL
    .
    anyway.. thanks again! :)
     
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    I feel you. Going through the same problems with the "New Input System".

    Having to register for callbacks is mentioned in several places in the docs. For example, right on the first page "Connect and Callbacks".

    If your class inherits from MonoBehaviourPunCallbacks, you don't always have to register. OnEnable and OnDisable take care of that then. Just make sure that override methods call their base and it will work.