Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Unable to check if Unity interstitial is Loaded [SOLVED]

Discussion in 'Unity Ads & User Acquisition' started by gamesjust007, Jul 14, 2023.

  1. gamesjust007

    gamesjust007

    Joined:
    Jan 3, 2017
    Posts:
    13
    Hi there,
    It is latest Unity, i.e. Unity 2022.3.4f1 and latest Unity Ads (Legacy) Package 4.4.2
    {Using Legacy package because I live in Pakistan and Iron Source is not available for Pakistan, LOL).
    So I am implementing Unity Interstitial and the interface OnUnityAdsAdLoaded is not even called.
    I have checked if OnUnityAdsShowComplete is called or not, it is called fine and the result is shown either Skipped or Completed depending on ad closing but I am unable to check if ad is loaded or not.
    I am using the following code:
    public void OnUnityAdsAdLoaded(string placementId)
    {
    unityAdLoaded = true;
    }

    In other class I check if this static bool unityAdloaded is true then show ad, it is never true.

    Kindly help me here.

    Regards
     
  2. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    597
  3. gamesjust007

    gamesjust007

    Joined:
    Jan 3, 2017
    Posts:
    13
    Hi,
    Thanks for replying. Yes registered the Initialization script with IUnityAdsInitializationListener and the Interstitial class with both IUnityAdsLoadListener and IUnityAdsShowListener
    I am attaching my script with this comment. These are the scripts that I am using, first for initializing the ads and the other one to load Interstitial ads. Where I need to call Unity Interstitial, I want to access the static boolean "unityAdLoaded" check if the interstitial is loaded then I will request Unity Interstitial ad.

    Please do let me know if anything you think is confusing.

    Regards.
     

    Attached Files:

  4. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    597
    After you called the Advertisement.Load method, OnUnityAdsAdLoaded or OnUnityAdsFailedToLoad will be called, please print the error and message in the OnUnityAdsFailedToLoad method.

    upload_2023-7-18_11-49-26.png
     
  5. gamesjust007

    gamesjust007

    Joined:
    Jan 3, 2017
    Posts:
    13
    Dear @SamOYUnity3D,
    Thanks for your kind response.
    Actually the OnAdsFailedToLoad will never be called since the ad is Loaded. In the scripts attached, in UnityInterstitial in the callback OnUnityAdsAdLoaded I have a boolean unityAdLoaded which turns to true if this callback is called.

    Now I have attached another script attached to a GameObject. When I try to show ad with following method
    if (UnityInterstitial.unityAdLoaded)
    {
    unityInter.ShowAd();
    }
    The ad is not shown here.


    However, when I attempt to show ad without checking:
    public void TestAdButton()
    {
    unityInter.ShowAd();
    }

    It shows ad just fine!

    Please let me know if it is Ok to share the Test Project with you that I am using so that you can simply run and check it.
     

    Attached Files:

  6. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    597
    Yes, you can share the test project with us and we will check it.
     
  7. gamesjust007

    gamesjust007

    Joined:
    Jan 3, 2017
    Posts:
    13
    Dear @SamOYUnity3D ,
    Thank you so much for your time. I figured out the issue while testing rewarded ads.
    While implementing the rewarded ads, the same callback was not being called so I read on Unity Forums that we can not see rewarded ads in Editor and we need to build and test on a device. That's the answer!

    For people's reference:
    If you want to check whether Unity Interstitial or rewarded ad is loaded in OnUnityAdsAdLoaded callback, build it and run in your Android or iOS device. It somehow works only in devices and not in Editor.

    Thanks for your time again @SamOYUnity3D !
     
    SamOYUnity3D likes this.