Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question Ads (Unity Ads) pause the multiplayer (Netcode) game and the connection is lost

Discussion in 'Multiplayer' started by ycm-dev, Feb 25, 2023.

  1. ycm-dev

    ycm-dev

    Joined:
    Mar 9, 2022
    Posts:
    6
    When I use interstitial ads, the ad normally take more time than the refresh time of the multiplayer connection.

    So when the players come back to the game, their games have been "paused" and they have not been sending the heartbeat signal for the connection being refreshed. If it happens to the host, the game is lost.

    How can I make that the paused game during the ad keep sending those refresh heartbeat, or at least other way of fixing it.

    (It also happens if the host is innactive for a while, but I understand that it happens, since the host may have left. But what I don't agree is that it happens with ads).

    Thank you very much!
     
  2. doomcityofkings

    doomcityofkings

    Joined:
    Apr 11, 2020
    Posts:
    21
    bump i am having same issue
     
  3. b4guw1x

    b4guw1x

    Joined:
    Apr 16, 2020
    Posts:
    43
    Maybe checking your app as running on background can help? I don't know i just assume.

    To check this setting
    In the editor, go to Edit → Project Settings → Player. The inspector pane will now change to show the player settings. Look for the option that says "Run In Background" and check it. This option will be held in both the editor preview and in built games.

    With that it may continue to send packages so maybe it helps.
     
  4. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,138
    On mobile when your app goes to the background this happens, the only ways to handle this are A don't show ads mid-game and B reconnect the user to the same session when they are back.

    At least up to iOS 14, on IOS there was no way around this.
     
    doomcityofkings likes this.
  5. doomcityofkings

    doomcityofkings

    Joined:
    Apr 11, 2020
    Posts:
    21
    do u know a method to reconnect them back? just example or where to go
     
  6. doomcityofkings

    doomcityofkings

    Joined:
    Apr 11, 2020
    Posts:
    21
    already made that xD i think its because Admob set timescale to 0 or something
     
  7. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,138
    Well first of all store the ip and port that the game connects to with any session token/match making ticket somewhere like in player prefs or in variables so you can re-use them.

    Then when you disconnect, and when you have OnApplicationFocus callbacks, you can try to reconnect to those.

    You can send some additional data when connecting to indicate a reconnect so the server can find you data and attach them to you again.

    Also runInBackground helps this not happening on PC but not on mobile.
     
    doomcityofkings likes this.
  8. doomcityofkings

    doomcityofkings

    Joined:
    Apr 11, 2020
    Posts:
    21
    this give me idea on what to do in future thanks alot.
     
  9. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,138
    No worries