First Android Game - Part 16 - Clients Selecting QuitAug 22, 2023This is part 16 of making my first Android Game. If you missed part15, you can find it hereCurrently the users can quit the game by selecting "Quit" on the WhatYouHaveMenu. The "Quit" code is using SceneManager.LoadScene(quitToMainScene); When the client quits, this is what the master looks like. You can see that the client character stays and then another one rejoinsWhen the client quits, this is what the client looks like. You can see that even in the main menu scene, the coins and enemies are still spawning. The client then rejoins the game even though I did not select connectI clearly don't understand what happens when user quits the game by closing the app or selecting "Quit" from the WhatYouHaveMenu. So In GameManager.cs I addeded PUN Callbacks: OnDisconnected(Photon.Realtime.DisconnectCause cause), OnLeftRoom(), OnMasterClientSwitched(Photon.Realtime.Player newMasterClient) and OnPlayerLeftRoom(Photon.Realtime.Player otherPlayer)I added Debug.Logs into each of those callbacks. I tested what happens when user quits the app by closing the app vs when the user selects "Quit" from the WhatYouHaveMenu which is calling SceneManager.LoadScene(quitToMainScene). I first tested selecting "Quit" from the menu, there were no Debug.Logs(). However, in the editor, if I quit play mode, OnLeftRoom() and OnDisconnected() gets calledIf the editor was the master and mobile was the client, and mobile closes the app. OnPlayerLeftRoom() would get called in the editor console. However, if the mobile was the master instead and the editor was the client, then OnPlayerLeftRoom() and OnMasterClientSwitched would get called in the editor consoleThe conclusion is selecting "Quit" from the WhatYouHaveMenu does nothing in terms of leaving the room or server. Looking at the Asteroid example, I see that in their OnLeftRoom(), they would call PhotonNetwork.Disconnect. So I thought I try calling PhotonNetwork.Disconnect() when the user selects "Quit". This did not work and threw an error "operation set (252) not called because client is not connected"I then noticed in the Asteroid Game example, in the OnDisconnected() they would call UnityEngine.SceneManager.LoadScene(). So I removed the LoadScene from OnQuitClick(). I saw that OnLeftRoom() would get called first then OnDisconnected() would get called next. So In OnLeftRoom(), that's where I would call the loadscene. Now when the client drops out, it can join lobbies and roomes again. If the master drops out, the client will still become the master due to the implementation from the previous blogFrom the result below is the recording of the master. When the client drops out, the client would not rejoin, and also disappears!From the result below is the recording of client. When the client drops out, the coins and enemies don't spawn on the client side. The client can also join the lobby and create rooms!Check out blog 17 hereRecent blogsSee all blogs