Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Unity Ads Banner no show Android

Discussion in 'Unity Ads & User Acquisition' started by GeerRebot, Feb 26, 2024.

  1. GeerRebot

    GeerRebot

    Joined:
    Oct 13, 2022
    Posts:
    6
    hi, interstitial and rewarded ads work on Android, but the banner does not appear when you load it and then display it, why?

    this is the banner code

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.Advertisements;
    public class BannerAds : MonoBehaviour
    {
    [SerializeField] private string androidAdUnitId;
    [SerializeField] private string iosAdUnitId;
    private string adUnitId;
    private void Start()
    {
    #if UNITY_IOS
    adUnitId = iosAdUnitId;
    #elif UNITY_ANDROID
    adUnitId = androidAdUnitId;
    #endif
    // Set the banner position:
    Advertisement.Banner.SetPosition(BannerPosition.BOTTOM_CENTER);
    }
    public void LoadBanner()
    {
    // Set up options to notify the SDK of load events:
    BannerLoadOptions options = new BannerLoadOptions
    {
    loadCallback = OnBannerLoaded,
    errorCallback = OnBannerError
    };
    // Load the Ad Unit with banner content:
    Advertisement.Banner.Load(adUnitId, options);
    }
    public void ShowBannerAd()
    {
    // Set up options to notify the SDK of show events:
    BannerOptions options = new BannerOptions
    {
    clickCallback = OnBannerClicked,
    hideCallback = OnBannerHidden,
    showCallback = OnBannerShown
    };
    // Show the loaded Banner Ad Unit:
    Advertisement.Banner.Show(adUnitId, options);
    }
    void HideBannerAd()
    {
    Advertisement.Banner.Hide();
    }
    //Region 1
    void OnBannerHidden() { }
    void OnBannerClicked() { }
    void OnBannerShown() { }
    //Region 2
    void OnBannerError(string message) { }
    void OnBannerLoaded() { }
    }
     
  2. Yasuyuki

    Yasuyuki

    Unity Technologies

    Joined:
    Sep 11, 2014
    Posts:
    166
    Do you initialize Unity Ads SDK in another script? I couldn't find initialize() in your code.
    Also, can you make sure that Unity Ads SDK completed initializing successfully before load()?
     
  3. GeerRebot

    GeerRebot

    Joined:
    Oct 13, 2022
    Posts:
    6
    the script to initialize the ads and the banner are in an object, and when I play the scene I get the debug that the ads initialized

    this is the initialize ads code

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.Advertisements;
    public class InitializeAds : MonoBehaviour ,IUnityAdsInitializationListener
    {
    [SerializeField] private string androidGameId;
    [SerializeField] private string iosGameId;
    [SerializeField] private bool testMode;
    private string gameId;
    public void Awake()
    {
    #if UNITY_IOS
    gameId = iosGameId;
    #elif UNITY_ANDROID
    gameId = androidGameId;
    #elif UNITY_EDITOR
    gameId= androidGameId;
    #endif
    if (!Advertisement.isInitialized && Advertisement.isSupported)
    {
    Advertisement.Initialize(gameId, testMode, this);
    }
    }
    public void OnInitializationComplete()
    {
    Debug.Log("Ads Initialized");
    }
    public void OnInitializationFailed(UnityAdsInitializationError error, string message) { }
    }
     
  4. Yasuyuki

    Yasuyuki

    Unity Technologies

    Joined:
    Sep 11, 2014
    Posts:
    166
    I think you'll need to check if Advertisement.isInitialized before Advertisement.Banner.Load()
    Also worth checking if there are any error messages in the OnBannerError callback.