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

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!

bump i am having same issue

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.

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.

1 Like

do u know a method to reconnect them back? just example or where to go

already made that xD i think its because Admob set timescale to 0 or something

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.

1 Like

this give me idea on what to do in future thanks alot.

No worries