Hello. We are creating a small mobile multiplayer game using Relay and NGO where a host allows one other player to connect and interact. In our test project, we are simply changing the state of a colored box and validating to each other that the host was able to update the color and the client sees it. This is all working great, except for situations where the host or client appears to lose connection to the relay service.
This is most easily reproducible when the host or client switches applications on their mobile device and then switches back to the test project. There have been instances where we have been able to switch apps fine and still have a connection, but is not consistent. Is there any information that could be shared as to why this connection drops when switching apps on a mobile phone?
This is not a major concern for us at the moment, but you can imagine a situation where a host or client suddenly receives a phone call or text, and needs to swap out briefly to respond and comes back to find they’ve been disconnected or their session is otherwise lost. Not a great multiplayer experience. Any thoughts or suggestions?
Thanks so much for the additional details! I have forwarded this to Engineering, and I will let you know if they have any additional follow up questions!
The (just released) version 1.2.0 of the com.unity.transport package contains a fix for the issue where switching applications would cause the connection to fail. You can upgrade directly from the package manager.
Note however that if the application is in the background for more than ~10 seconds, then it is likely that the client’s allocation in the Relay server will have timed out. Unfortunately, we can’t recover automatically from that since it requires creating a new allocation through the Relay SDK.
If using the transport package directly, it is possible to detect the above condition by calling NetworkDriver.GetRelayConnectionStatus. If using Netcode for GameObjects, then the callback NetworkManager.OnTransportFailure will be invoked when the Relay allocation times out. Note that due to another bug, these mechanisms are sometimes unreliable (it’s possible they won’t detect when the allocation times out). Unfortunately the fix for that bug didn’t make it into 1.2.0.