I tried putting Google Ads into my Unity app and I've ran into a weird issue. When I request an interstitial ad, I receive the AdLoaded event, but interstitialAd.IsLoaded() still returns false. If I show the ad, it doesn't give any errors and shows it.
What I'm using:
Unity version 2020.3.2
Google AdMob 5.4.0 (https://github.com/googleads/googleads-mobile-unity/releases/tag/v5.4.0)
I'm currently using test ads because it's my first time using Google Ads in a Unity project, could it be that?
My AdsManager script:
using System; using System.Collections; using UnityEngine; using GoogleMobileAds.Api; public class AdsManager : MonoBehaviour { //Sample app ID: ca-app-pub-3940256099942544~3347511713 private static readonly string appId = "ca-app-pub-3940256099942544/3419835294"; private static readonly string bannerId = "ca-app-pub-3940256099942544/6300978111"; private static readonly string interstitialId = "ca-app-pub-3940256099942544/1033173712"; private static readonly string rewardedId = "ca-app-pub-3940256099942544/5224354917"; private static readonly string rewardedInterstitialId = "ca-app-pub-3940256099942544/5354046379"; private static readonly string nativeId = "ca-app-pub-3940256099942544/2247696110"; public BannerView bannerAd; public InterstitialAd interstitialAd; IEnumerator Start() { while(Application.internetReachability == NetworkReachability.NotReachable) { yield return null; }; MobileAds.Initialize(InitializationStatus => {}); this.RequestInterstitial(); } public AdRequest CreateAdRequest() { return new AdRequest.Builder().Build(); } public void RequestInterstitial() { Debug.Log("Requesting interstitial ad"); if(this.interstitialAd != null) { this.interstitialAd.Destroy(); }; this.interstitialAd = new InterstitialAd(interstitialId); this.interstitialAd.OnAdClosed += HandleOnInterstitialAdClosed; this.interstitialAd.OnAdFailedToLoad += HandleOnInterstitialAdFailedToLoad; this.interstitialAd.OnAdLoaded += HandleOnInterstitialAdLoaded; this.interstitialAd.LoadAd(this.CreateAdRequest()); //ShowInterstitial(); - didn't show the ad } public void ShowInterstitial() { if(this.interstitialAd.IsLoaded()) { Debug.Log("Showing interstitial ad"); //didn't log this.interstitialAd.Show(); } } public void HandleOnInterstitialAdFailedToLoad(object sender, AdFailedToLoadEventArgs args) { Debug.Log("HandleFailedToReceiveInterstitialAd event received with message: " + args.Message); //never called } public void HandleOnInterstitialAdLoaded(object sender, EventArgs args) { Debug.Log("HandleInterstitialAdLoaded event received"); //does log Debug.Log("Is interstitial ad loaded? " + this.interstitialAd.IsLoaded()); //Logs "Is interstitial ad loaded? False" this.interstitialAd.Show(); //shows the ad without any issues } }
What I'm using:
Unity version 2020.3.2
Google AdMob 5.4.0 (https://github.com/googleads/googleads-mobile-unity/releases/tag/v5.4.0)
I'm currently using test ads because it's my first time using Google Ads in a Unity project, could it be that?
My AdsManager script:
using System; using System.Collections; using UnityEngine; using GoogleMobileAds.Api; public class AdsManager : MonoBehaviour { //Sample app ID: ca-app-pub-3940256099942544~3347511713 private static readonly string appId = "ca-app-pub-3940256099942544/3419835294"; private static readonly string bannerId = "ca-app-pub-3940256099942544/6300978111"; private static readonly string interstitialId = "ca-app-pub-3940256099942544/1033173712"; private static readonly string rewardedId = "ca-app-pub-3940256099942544/5224354917"; private static readonly string rewardedInterstitialId = "ca-app-pub-3940256099942544/5354046379"; private static readonly string nativeId = "ca-app-pub-3940256099942544/2247696110"; public BannerView bannerAd; public InterstitialAd interstitialAd; IEnumerator Start() { while(Application.internetReachability == NetworkReachability.NotReachable) { yield return null; }; MobileAds.Initialize(InitializationStatus => {}); this.RequestInterstitial(); } public AdRequest CreateAdRequest() { return new AdRequest.Builder().Build(); } public void RequestInterstitial() { Debug.Log("Requesting interstitial ad"); if(this.interstitialAd != null) { this.interstitialAd.Destroy(); }; this.interstitialAd = new InterstitialAd(interstitialId); this.interstitialAd.OnAdClosed += HandleOnInterstitialAdClosed; this.interstitialAd.OnAdFailedToLoad += HandleOnInterstitialAdFailedToLoad; this.interstitialAd.OnAdLoaded += HandleOnInterstitialAdLoaded; this.interstitialAd.LoadAd(this.CreateAdRequest()); //ShowInterstitial(); - didn't show the ad } public void ShowInterstitial() { if(this.interstitialAd.IsLoaded()) { Debug.Log("Showing interstitial ad"); //didn't log this.interstitialAd.Show(); } } public void HandleOnInterstitialAdFailedToLoad(object sender, AdFailedToLoadEventArgs args) { Debug.Log("HandleFailedToReceiveInterstitialAd event received with message: " + args.Message); //never called } public void HandleOnInterstitialAdLoaded(object sender, EventArgs args) { Debug.Log("HandleInterstitialAdLoaded event received"); //does log Debug.Log("Is interstitial ad loaded? " + this.interstitialAd.IsLoaded()); //Logs "Is interstitial ad loaded? False" this.interstitialAd.Show(); //shows the ad without any issues } }