Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Banner AD behaviour

Discussion in 'Unity Ads' started by ihgyug, Aug 9, 2019.

  1. ihgyug

    ihgyug

    Joined:
    Aug 5, 2017
    Posts:
    186
    Hi,

    On my loading screen, I currently enable a banner ad on top simply using :
    Code (CSharp):
    1. Advertisement.Banner.Show("myBannerID");
    and then, just before activating the new scene, I use
    Code (CSharp):
    1. Advertisement.Banner.Hide(false);
    All great and fun, the banner shows when the loading start and it hides when it's complete.
    But I recently received a review stating that the banner, sometime, shows up on the next scene and it remains there.
    I have not been able to replicate this bug, but I think what happens is that the banner loads async and manages to show up only after the loading.

    Is it intended behaviour? Shall I rather use a coroutine + Advertisement.Banner.Load and simply do not call Advertisement.Banner.Show() if it didn't manage to load and the scene load is done?

    Thank you
     
    Last edited: Aug 9, 2019
  2. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,459
    I don't think that is intended behavior, but I think you may be right that it is probably a timing issue with Banner.Show.

    I would recommend using Banner.Load in combination with the BannerLoadOptions callbacks:

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using UnityEngine.Advertisements;
    4.  
    5. public class BannerExample : MonoBehaviour
    6. {
    7.     public string gameId = "1234567";
    8.     public string placementId = "bannerAd";
    9.     public bool testMode = true;
    10.  
    11.     void Start()
    12.     {
    13.         Advertisement.Initialize(gameId, testMode);
    14.         LoadBanner();
    15.     }
    16.  
    17.     public void LoadBanner()
    18.     {
    19.         if (!Advertisement.Banner.isLoaded)
    20.         {
    21.             BannerLoadOptions loadOptions = new BannerLoadOptions
    22.             {
    23.                 loadCallback = OnBannerLoaded,
    24.                 errorCallback = OnBannerError
    25.             };
    26.             Advertisement.Banner.Load(placementId, loadOptions);
    27.         }
    28.     }
    29.     void OnBannerLoaded()
    30.     {
    31.         Debug.Log("Banner Loaded");
    32.         Advertisement.Banner.Show(placementId);
    33.     }
    34.     void OnBannerError(string error)
    35.     {
    36.         Debug.Log("Banner Error: " + error);
    37.     }
    38. }
     
unityunity