I’m trying to dissect the UGS sample project but am having a hard time understanding the way to properly handle a player whose disconnected, and those who have disconnected but attempt to reconnect to the game. I’m using Lobbies and Relay to handle the matchmaking, and Netcode for game objects to handle the multiplayer game logic.
I’m working on a mobile game, and what I’ve noticed is that disconnects seem to happen frequently, and are guaranteed to happen if the player switches from wifi to cellular data, or travels a good distance on cellular data. Here’s the usecase I’m trying to accomplish:
-
When a player (host or client) detects that other player has disconnected, pause all in-game logic and actions and display a message that a player has disconnected, with a 30 seconds timer appearing as the window of time allowing the player to reconnect.
-
When a player is disconnected permanently and doesn’t come back, what’s the proper sequence of methods to call to shutdown the connection and lobby, so that there’s no issues in trying to find a new matchmaking game? What I’m doing right now I think is overkill… not sure if it’s right:
-
First I call this method to delete the lobby:
public async void DeleteLobby(string LobbyID){
try
{
await LobbyService.Instance.DeleteLobbyAsync(LobbyID);
NetworkManager.Singleton.ConnectionApprovalCallback -= ApprovalCheck;
StopAllCoroutines();
}
catch (LobbyServiceException e)
{
Debug.Log(e);
}
}
-
Then I call the NetworkManager method “Shutdown”. Is this the proper way to end a game, regardless of if the player is host or client?
-
To check if a player is disconnected, right now I’m getting all of the players from the Lobby and if the count is less than 2, I know a player has disconnected (my game is only 2 players). What’s the best way to go about detecting a disconnected player?
-
What methods should be used in what sequence for a disconnected player to detect they have disconnected, and then attempt to reconnect to the game they were in?
-
Is the disconnected detection instant? I’m wondering what happens if either the host or client makes an RPC call before the player is detected as disconnected… will the RPC call stay in queue until reconnection, or will it be lost? How should I handle the game logic to make sure nothing gets executed, or that anything that was executed is queued up to run when the player returns?
Any help with any of this would be very much appreciated!