Search Unity

Question Joining a game already in session?

Discussion in 'Lobby' started by Rom-, Oct 17, 2022.

  1. Rom-

    Rom-

    Joined:
    Nov 26, 2008
    Posts:
    90
    Hello,

    I'm wondering if you can join a game already in session with Lobby and Relay? If so, how would one go about this?

    Thanks,
    -Brett
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,848
    Theoretically speaking, I imagine that once a Lobby-based game session has started it works like any other Netcode for GameObjects networking session. That means in order for clients to connect mid-game they would have to know the server's IP address and port.

    This wouldn't be impossible to get but it would only be practical for clients who already were in the session to reconnect, since the server could easily relay the current IP address and port to joined clients, and clients could then use this info to attempt to reconnect to the most recent game session. However, if the server/host has started a new game in the meantime, the client might end up joining a completely different session altogether.

    Hopefully someone with authority can give a definite answer, I'm interested in this myself.
     
  3. veleek_unity

    veleek_unity

    Ben Randall Unity Technologies

    Joined:
    Aug 25, 2021
    Posts:
    59
    Yes, there is nothing special about the state of a Lobby or Relay that should prevent this. The Lobby will contain the current connection details of either the Relay (if being used) or the Host Server (if using a DGS or a P2P server). You could find and join the Lobby and then use the connection details to find the correct host.

    After you've connected, it up to the game logic to do the "right" thing. If it's a game like Minecraft where there's no "thing" that's happening, the game client just needs to load up the current world state and start playing.

    Side note: If you DON'T want this to happen in you game, you can mark the Lobby as Locked which prevent new users from joining. This would be useful for a game like a Battle Royale game where it doesn't make sense to have people joining mid-game.
     
    MarcoZVincenzi likes this.