Search Unity

What to do when Network is unavailable

Discussion in 'Unity Ads & User Acquisition' started by Christop, Dec 6, 2014.

  1. Christop

    Christop

    Joined:
    Aug 21, 2012
    Posts:
    60
    Hi
    I am unsure what is happening with UnityAdds when there is no network connection.
    I am playing around with the examples and can not find a pattern.

    1) What happens when there is a network connection on start and the Initialization succeeds,
    afterwards during the game the network connection is lost. Will the ads still play because of caching? Or will isReady() return always false.

    2) What if initially there is no network connection so that Initialization will fail (will it fail or will it try indefinitely to reconnect?)… But then during the game the network connection is restored. In the documentation it is stated that you can call Initialize() only once. Will the game have no ads until it is closed because you called Initialize when there was no connection?

    Thanks
    Dimi
     
    reddtoric likes this.
  2. Christop

    Christop

    Joined:
    Aug 21, 2012
    Posts:
    60
    Hi UnityAds team,
    can you please comment on this.
    I think these are valid questions that are not referenced elsewhere.

    Thanks
    Dimi
     
    reddtoric likes this.
  3. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    Hi Dimi,

    These are good questions.

    1) If a network connection is established and Unity Ads is able to be initialized, and it successfully receives a response for ad request data, Unity Ads then attempts to cache video ads. If the network is not available at the time of showing an ad, Unity Ads shows the ad only if it has already been cached. Otherwise no ad will be shown.

    2) If no network is available when the app attempts to initialize Unity Ads, it can still be initialized if ad data was previously requested and there is are till cached video ads available on the device. If it fails to initialized, you could attempt to initialize ads again shortly before showing an ad, but keep in mind that it can take a few seconds to initialize and retrieve ad request data.

    In any case, if Unity Ads fails to initialize, or retrieve ad request data, or is unable to cache or stream video ads, then ads will not be shown. We are working to improve network error handling. Currently, poor network traffic or background downloads can potentially cause playback errors when viewing ads.

    Hope that helps.
     
    Salazar likes this.
  4. Christop

    Christop

    Joined:
    Aug 21, 2012
    Posts:
    60
    Hi thanks for the answers.
    So you say that one can call the Initialization function multiple times, until it Initialization succeeds.
    So is it sensible to have it be called on every level load (testing the isInitialized bool) to cover the case of a network connection not being available on startup?

    Thanks
    Dimi
     
  5. Christop

    Christop

    Joined:
    Aug 21, 2012
    Posts:
    60
    Well I have a case which somewhat strange,
    I modified you UnityAdsHelper class to function as a Singleton, which is also persistent using the DontDestroyOnLoad() function . THis means the Initialization part of it in the Awake() function is only called once. At the start of the first level in my test game.

    So when network is off when running the first level the Initialization code is never run again and i should never see ads.
    After level 1 you go to level 2 where you stay indefinitely (level2 is played over and over again).
    In level two, i test the isReady() flag of the persistent UnityAdsHelper class and if ok show the ad.
    When wifi is off no ads are shown as you described.

    Now when I turn on wifi during level2, then at some point I see in the xcode console unity ads code and the ads magically start to appear. Please note that the Initialization function is never called in level2.
    I user the test mode to initialize the ads in level1.

    So my question is. Can it be that even when there is no network when the UnityAds Initialization() function is initially called, that it will stay in the background and try from time to time to Initialize() on its own?

    Thanks
    Dimi
     
  6. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    Ah, you're right. Sorry, I forgot that isReady can also trigger an adrequest to the server. Normally it's done during initialization, ideally when you first load the application.

    You're correct, once initialized, unity ads will stay in the background. So it's not necessary to keep calling initialization. Just call isReady to check again if ads are available and ready to show.
     
    Salazar likes this.
  7. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    235
    Hi,

    My Unity-Ads script has Advertisement.allowPrecache = true; statement. But when it shows video ad, its buffering the video. Is it buffers online or local? (I initialize ads in first scene, use it in 3rd scene)

    Regards
     
  8. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    The allowPrecache property doesn't actually do anything at the moment other than return a value equal to true. The setter for the property is empty. The next available ad is always cached as soon as it is possible.

    The ads aren't actually being buffered when you see the buffering message. I thought we had removed that message. Should be on it's way out if it isn't already.
     
    Salazar likes this.
  9. ez06

    ez06

    Joined:
    Feb 18, 2014
    Posts:
    45
    Hi there,

    It seems the Initialization does NOT work when the phone is not connected from the internet (Advertisement.isInitialized returns false after the attempt). Then when I try either Initialize("12345") or "if (Advertisement.isReady() == false)", I don't get anything in the log. The video ads never get cached. They only do if the game had internet when the first Initialization attempt occured.

    Why does Initialize() not work when I call it again, when isInitialized return false?
     
  10. coolamigo

    coolamigo

    Joined:
    Mar 28, 2020
    Posts:
    25
    This is further confusing me now. in 2020, I would only expect things to run more smoothly.
    I am running Advertisement.Show(placement) inside of isReady check, but if I start with internet turned off, it never shows an ad. I am only testing inside of Unity, so if that is the reason, please inform.

    Also, can we Debug.Log(Advertisement.isReady) to ensure loading of advertisementsif not already loaded.

    Please respond
     
  11. kyle-unity

    kyle-unity

    Unity Technologies

    Joined:
    Jan 6, 2020
    Posts:
    336
    Hey @coolamigo, bear in mind the posts in this thread are from 5-6 years ago and probably don't reflect the functionality of the current up to date SDK.

    Have you tested on an actual device? The Ads SDK behaviour inside the editor works differently to when it is deployed in a build.

    The best way to check if a placement is ready is with either with IsReady or GetPlacementState:
    Code (CSharp):
    1. Debug.Log( Advertisement.IsReady(placementId) );
    2. Debug.Log( Advertisement.GetPlacementState(placementId) );
    The latter is useful to see if an error has occurred.
     
  12. coolamigo

    coolamigo

    Joined:
    Mar 28, 2020
    Posts:
    25
    Thank you, on devices, test ads are images rather than videos which makes me feel that they do not reflect the exact scenario. (Is it Ok to test on actual ones). I cannot connect my device which makes it cumbersome to test each change.
    actually, I am also getting these errors when I run without the internet:

    Invalid configuration request for gameId: 3561129
    System.Threading._ThreadPoolWaitCallback:performWaitCallback()
    Error: NameResolutionFailure
    System.Threading._ThreadPoolWaitCallback:performWaitCallback()

    But I can still play. Maybe ads are never getting Initialized
     
  13. coolamigo

    coolamigo

    Joined:
    Mar 28, 2020
    Posts:
    25
  14. Hoorza

    Hoorza

    Joined:
    May 8, 2016
    Posts:
    45
    I can confirm that while Ads won't re-initialize in the Editor when you got internet access again, no matter how long you wait. However, it does work on mobile (android to be precise, not tested on iOS). After re-enabling the internet connection ads will be available again. That was done in test mode.

    Unity version: 2020.1.4f1
    Advertisement package version: 3.4.9



    Hope it helps.