Ads not showing

I am in need of help because of ads.

This is my game: Too Deep To Dig – Apps no Google Play

The problem is: it does not shows ads.

I am using Advertisement 4.30 in Unity 2020.3.38f1, the ads should show in the beginning. The gameobject for the ads is summoned as a persistent object and start as soon the game starts.

In editor, it shows perfectly that everything is tuned, but not on the game.

Also, the test mode is FALSE.

Here is the code of the ad game object:

using System;
using UnityEngine;
#if ENABLE_INPUT_SYSTEM || UNITY_Android
using System.Collections;
using RPG.Control;
using UnityEngine.Advertisements;
public class AdManager : MonoBehaviour, IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener
{
    [SerializeField] private bool testMode = false;
    [SerializeField] private float delayInit = 0f;
    private string gameId = "4896638";
    private string video = "Level_Start";
    private bool showAd = true;
    private bool initializationIsComplete=false;
    private void Awake()
    {
        //#if UNITY_IOS
        //gameId = "4896639";
//#endif
        Advertisement.Initialize(gameId, testMode, this);
    }

    private void OnEnable()
    {
        LoadAd();
    }

    private void Update()
    {
        if (Time.timeSinceLevelLoad > delayInit && showAd)
        {
            ShowAd();
        }
    }

    // Load content to the Ad Unit:
    public void LoadAd()
    {
        // IMPORTANT! Only load content AFTER initialization.
        Debug.Log("Loading Ad: " + gameId);
        Advertisement.Load(gameId, this);
    }
    public void ShowAd()
    {
        if(!initializationIsComplete)
        {
            Debug.Log($"Trying to show and ad, but the system has not been initialized");
            return;
        }
        if(Advertisement.isInitialized)
        {
            Advertisement.Show(video, this);
        }
    }
    public void OnInitializationComplete()
    {
        print("Initialization complete.");
        initializationIsComplete = true;
    }
    public void OnInitializationFailed(UnityAdsInitializationError error, string message)
    {
        Debug.Log($"Unity Ads Initialization Failed: {error} - {message}");
    }
    public void OnUnityAdsAdLoaded(string placementId)
    {
        Debug.Log($"Ad Loaded: {placementId}");
    }
    public void OnUnityAdsFailedToLoad(string placementId, UnityAdsLoadError error, string message)
    {
        Debug.Log($"Error loading Ad Unit {placementId}: {error} - {message}");
    }
    public void OnUnityAdsShowFailure(string placementId, UnityAdsShowError error, string message)
    {
        Debug.Log($"Error loading Ad Unit {placementId}: {error} - {message}");
    }
    public void OnUnityAdsShowStart(string placementId)
    {
       
    }
    public void OnUnityAdsShowClick(string placementId)
    {
       
    }
    public void OnUnityAdsShowComplete(string placementId, UnityAdsShowCompletionState showCompletionState)
    {
        switch (showCompletionState)
        {
            case UnityAdsShowCompletionState.COMPLETED:
                showAd = false;
                break;
            case UnityAdsShowCompletionState.SKIPPED:
                showAd = false;
                break;
            case UnityAdsShowCompletionState.UNKNOWN:
                Debug.LogWarning("Ad Failed");
                break;
        }
    }
   
}
#endif

Hi, looking at your code I can see that LoadAd is called in the OnEnable function. This is likely causing your LoadAd call to occur before the SDK has fully initialized. I would advise moving this call to your OnInitializationComplete callback.
I would also make sure that you are calling to load an ad before every show call. The easiest way o do this is to call Load in the ShowComplete callback.

1 Like

Hey friend, thank you to answer, and sorry to take so long! I tried several manners to fix it in this mean time. But with no success. So, I made an APK and tried to debug adding an Text Mesh Pro Component to show the problem. It takes 10 seconds to answer something. The final message was:

"Error showing Ad Unit Level_Start: NOT_READY - Placement not ready.

Here is the new code:

using System;
using UnityEngine;
using System.Collections;
using RPG.Control;
using TMPro;
using UnityEngine.Advertisements;
public class AdManager : MonoBehaviour, IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener
{
    [SerializeField] private bool testMode = false;
    [SerializeField] private float delayInit = 5f;
    private string gameId = "4896638";
    private string video = "Level_Start";
    private bool showAd = true;
    private bool initializationIsComplete=false;
    private bool updateInitialization = true;

    [SerializeField] private TextMeshProUGUI debugLog;
    private int countDebugLog = 0;
    private void Update()
    {
        if (Time.timeSinceLevelLoad > delayInit && updateInitialization)
        {
           
            //#if UNITY_IOS
            //gameId = "4896639";
//#endif
            Advertisement.Initialize(gameId, testMode, this);
            updateInitialization = false;
            return;
        }  
       
        if (Time.timeSinceLevelLoad > delayInit && showAd)
        {
            ShowAd();
        }
    }

    // Load content to the Ad Unit:
    public void LoadAd()
    {
        if (showAd==false)
        {
            return;
        }
        // IMPORTANT! Only load content AFTER initialization.

        string debugText = "Loading Ad: " + gameId;
       
        Debug.Log(debugText);
       
        ShowDebug(debugText);
       
        Advertisement.Load(gameId, this);
    }
    public void ShowAd()
    {
        if(!initializationIsComplete)
        {
            //string debugText = $"Trying to show and ad, but the system has not been initialized";
            Debug.Log($"Trying to show and ad, but the system has not been initialized");
            //ShowDebug(debugText);
            return;
        }
        if(Advertisement.isInitialized)
        {
            showAd = false;
            LoadAd();
            Advertisement.Show(video, this);
        }
    }
    public void OnInitializationComplete()
    {
        print("Initialization complete.");
        delayInit = delayInit + Time.timeSinceLevelLoad;
        initializationIsComplete = true;
    }
    public void OnInitializationFailed(UnityAdsInitializationError error, string message)
    {
        string debugText = $"Unity Ads Initialization Failed: {error} - {message}";
        Debug.Log($"Unity Ads Initialization Failed: {error} - {message}");
        ShowDebug(debugText);
        updateInitialization = true;
        showAd = true;
    }
    public void OnUnityAdsAdLoaded(string placementId)
    {
        Debug.Log($"Ad Loaded: {placementId}");
    }
    public void OnUnityAdsFailedToLoad(string placementId, UnityAdsLoadError error, string message)
    {
        string debugText = $"Error loading Ad Unit {placementId}: {error} - {message}";
        Debug.Log($"Error loading Ad Unit {placementId}: {error} - {message}");
        ShowDebug(debugText);
        showAd = true;
    }
    public void OnUnityAdsShowFailure(string placementId, UnityAdsShowError error, string message)
    {
        string debugText = $"Error showing Ad Unit {placementId}: {error} - {message}";
        Debug.Log($"Error showing Ad Unit {placementId}: {error} - {message}");
        ShowDebug(debugText);
        showAd = true;
    }
    public void OnUnityAdsShowStart(string placementId)
    {
       
    }
    public void OnUnityAdsShowClick(string placementId)
    {
       
    }
    public void OnUnityAdsShowComplete(string placementId, UnityAdsShowCompletionState showCompletionState)
    {
        //LoadAd();
        switch (showCompletionState)
        {
            case UnityAdsShowCompletionState.COMPLETED:
                //showAd = false;
                break;
            case UnityAdsShowCompletionState.SKIPPED:
                //showAd = false;
                break;
            case UnityAdsShowCompletionState.UNKNOWN:
                Debug.LogWarning("Ad Failed");
                ShowDebug("Ad Failed");
                break;
        }
    }

    private void ShowDebug(string debugText)
    {
        string newText = debugLog.text;
        if (countDebugLog == 0)
        {
            newText = debugText;
        }
        else if (countDebugLog < 12)
        {
            newText = String.Concat(newText, Environment.NewLine, debugText);
        }
        else
        {
            newText = debugText;
            countDebugLog = 0;
        }

        debugLog.text = newText;
        ++countDebugLog;
    }
   
}

Hi @hearnodarkness looking at your code I can see that you are calling Advertisement.Show without leaving sufficient time for the SDK to load an ad. That’s why you are seeing the placement not ready error. Please ensure that you have loaded an ad completely before trying to display it.

Hey friend, thank you for the answer. I changed for 10 minutes and even so I had the same exactly problem.

Hi, I have attached a sample script, can you test it out and check is it working for you?

8540561–1141106–AdsScript.cs (2.71 KB)

I changed one thing or other to make it like I want…
I cannot believe… it works!!! I will put in production to confirm but it worked on APK!
Thank you so much!!!