Search Unity

Question Avoid mobile disconnects from Relay when swapping applications on phone

Discussion in 'Relay' started by jeremy_hgs, Jul 5, 2022.

  1. jeremy_hgs

    jeremy_hgs

    Joined:
    Sep 12, 2019
    Posts:
    7
    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?
     
    NelsonChristensen likes this.
  2. emilyryan

    emilyryan

    Unity Technologies

    Joined:
    Nov 22, 2019
    Posts:
    129
    Hello! I am sorry to hear you're experiencing issues with Relay when backgrounding your application!

    Engineering has reproduced this issue on iOS and is working towards a fix that will be included in an upcoming release.

    What types of mobile devices are you testing on? Are you seeing this just on iOS, or have you seen this Android as well? Thanks for your time!
     
  3. jeremy_hgs

    jeremy_hgs

    Joined:
    Sep 12, 2019
    Posts:
    7
    Hi @emilyryan thanks for the quick response and repro! We're actually currently experiencing this on Android. Our devices are as follows:

    Phone 1 - Galaxy S21 Ultra 5G (Verizon). Android version: 12
    Phone 2 - Galaxy S21 Ultra 5G (AT&T). Android version: 12

    Please let me know if I can provide additional information that'll be useful to you and the team. Thank you again!
     
  4. emilyryan

    emilyryan

    Unity Technologies

    Joined:
    Nov 22, 2019
    Posts:
    129
    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!
     
    jeremy_hgs likes this.
  5. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    441
    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.