Search Unity

Third Party PUN2 - Question Regarding Code

Discussion in 'Multiplayer' started by jettzeong, Aug 29, 2021.

  1. jettzeong

    jettzeong

    Joined:
    Nov 5, 2018
    Posts:
    65
    Hi, may I know what is the difference between the callbacks OnJoinedRoom() and OnPlayerEnteredRoom()? To me it seems like both callbacks mean that the clients are joining a room, so is there any significant difference between them?

    upload_2021-8-29_21-8-22.png upload_2021-8-29_21-8-33.png

    For instance i would like to set up such that the game scene loads once 5 ppl are in the room. Which method should i use and why? Thanks
     
  2. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    As far as I understand it, OnJoinedRoom is called on all clients, whereas OnPlayerEnteredRoom is only called on clients that were already in the room, but not on the joining client.
     
    tobiass likes this.
  3. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,070
  4. jettzeong

    jettzeong

    Joined:
    Nov 5, 2018
    Posts:
    65
    I still have trouble understanding it unfortunately, do you mind giving an analogy on how it works?
     
  5. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    Let's assume you have set up something that logs a message to the screen for both callbacks.

    If you are joining a game, you as well as everyone already in the game will see the message logged in the OnJoinedRoom callback, but only those already in the game will see the message logged on the OnPlayerEnteredRoom callback, you wont.
     
    tobiass likes this.
  6. jettzeong

    jettzeong

    Joined:
    Nov 5, 2018
    Posts:
    65
    That makes it much clearer, thanks for the explanation!
     
    Munchy2007 likes this.