You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Closing the game on Android doesn't properly disconnect the client #3119
On Android, when quitting the app, the server and other players don't get notified. Eventually it will time out due to heartbeats, but that is not ideal. When quitting the game on other platforms, such as Windows, it correctly notifies the server, and the player prefab gets destroyed.
As far as I know, this is a limitation of mobile operation systems, android will instantly freeze the app when put in the background and will terminate the process nearly instantly as well when the user closes the app.
I'm interested if there is a workaround for this tho.
Hi,
On mobile (at least I just tested on android) you get some time to execute a bit of code before the application loses focus or is closed. However you need more than Application.wantsToQuit or Application.quitting, you need to hook to MonoBehaviour's OnApplicationFocus for when the app loses focus or OnApplicationPause for when the app is put in background or closed. If the app lost focus or is paused you can call Multiplayer ISession's LeaveAsync to close the session.
If instead you want to leave some grace timeout when the user puts the app in background before killing the session you can use the Lobby's Disconnect Removal Timeout that can be configured in your cloud dashboard/lobby settings.
Activity
Moe-Baker commentedon Nov 12, 2024
As far as I know, this is a limitation of mobile operation systems, android will instantly freeze the app when put in the background and will terminate the process nearly instantly as well when the user closes the app.
I'm interested if there is a workaround for this tho.
StephenHodgson commentedon Dec 3, 2024
We're also seeing this, which causes players to persist in the lobby indefinitely and blocks them from rejoining for some time.
Meta Quest 3
aondw commentedon Dec 9, 2024
Would love to have a solution/workaround for this too
mnachury-unity commentedon Nov 3, 2025
Hi,
On mobile (at least I just tested on android) you get some time to execute a bit of code before the application loses focus or is closed. However you need more than
Application.wantsToQuitorApplication.quitting, you need to hook to MonoBehaviour's OnApplicationFocus for when the app loses focus or OnApplicationPause for when the app is put in background or closed. If the app lost focus or is paused you can call Multiplayer ISession's LeaveAsync to close the session.If instead you want to leave some grace timeout when the user puts the app in background before killing the session you can use the Lobby's Disconnect Removal Timeout that can be configured in your cloud dashboard/lobby settings.