Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Unity ads 3.7.3: rewarded video ad not triggering OnUnityAdsShowComplete

Discussion in 'Unity Ads & User Acquisition' started by Bodin, Jul 21, 2021.

  1. Bodin

    Bodin

    Joined:
    Apr 19, 2017
    Posts:
    33
    Hi,

    I'm testing UnityAds with the code from this example.
    https://unityads.unity3d.com/help/unity/integration-guide-unity

    Unity version: 2018.4.22
    Unity ads version: 3.7.3
    Platform: Android
    Ads setting : Test Mode Enable
    All the code is exactly the same as in example.

    Initalizing & Ads load are working properly as it should be. I got the following log from console.
    "Unity Ads initialization complete."
    "Loading Ad: Rewarded_Android"
    "Ad Loaded: Rewarded_Android"

    but after Advertisement.Show had been called, the test ad appears.
    but after closing it, OnUnityAdsShowComplete doesn't trigger.
    (I also add Debug.Log at start of the function to check this)

    when I call Advertisement.Show again, I got error in console.
    "Error showing Ad Unit Rewarded_Android: NOT_READY - Placement Rewarded_Android is not ready"
    which means OnUnityAdsFailedToLoad was triggered.

    Could you please suggest what I did wrong?
    Thanks in advance & best regard
     
    DucaDiMonteSberna likes this.
  2. Schabbs

    Schabbs

    Joined:
    Aug 14, 2015
    Posts:
    3
    Hi,

    We are experiencing the same issue. Something seems to be wrong with the test ads. OnUnityAdsShowStart works as it's supposed to but OnUnityAdsShowComplete never triggers. The only difference in our configuration is that our Unity version is 2018.4.36f1 but everything else matches.
     
    Bodin and DucaDiMonteSberna like this.
  3. DucaDiMonteSberna

    DucaDiMonteSberna

    Joined:
    Jan 18, 2018
    Posts:
    34
    I have the exact same problem with my project
    Unity version: 2020.3.14f1
    Unity ads version: 3.7.3
    the problem persist even if I use the old "void HandleShowResult(ShowResult result)" method, not just the new OnUnityAdsShowComplete() if I thy to use in the new suggeste implementation
    "void HandleShowResult(ShowResult result)" using no listeners still works
     
    Bodin and onHead like this.
  4. onHead

    onHead

    Joined:
    Feb 11, 2016
    Posts:
    17
    I have same issue too.
    Unity version : 2021.1.12f
    Unity ads : 3.7.3

    Some ads have this problem
    ad type : playable
     
    Bodin likes this.
  5. Bodin

    Bodin

    Joined:
    Apr 19, 2017
    Posts:
    33
    My work around for now is, roll back Unity Ads to version 3.6.1, and use old callback method "OnUnityAdsDidFinish" instead of "OnUnityAdsShowComplete"

    so I supposed 3.7.3 still have some bug.
     
  6. DucaDiMonteSberna

    DucaDiMonteSberna

    Joined:
    Jan 18, 2018
    Posts:
    34
    funny thing is the old deprecated code stll works even on advertisement 3.7.3
    void ShowAd()
    {
    ShowOptions options = new ShowOptions();

    options.resultCallback = HandleShowResult;

    Advertisement.Show(adsPlacementId, options);
    }

    void HandleShowResult(ShowResult result)
    {
    if (result == ShowResult.Finished)
    {
    Debug.Log("Video completed - Offer a reward to the player");
    AddDonut();
    #if UNITY_ANALYTICS
    AnalyticsEvent.AdComplete(adsRewarded, adsNetwork, adsPlacementId);
    #endif
    }
    else if (result == ShowResult.Skipped)
    {
    //Debug.LogWarning("Video was skipped - Do NOT reward the player");
    #if UNITY_ANALYTICS
    AnalyticsEvent.AdSkip(adsRewarded, adsNetwork, adsPlacementId);
    #endif
    }
    else if (result == ShowResult.Failed)
    {
    //Debug.LogError("meh Video failed to show");
    #if UNITY_ANALYTICS
    AnalyticsEvent.AdSkip(adsRewarded, adsNetwork, adsPlacementId, new Dictionary<string, object> {
    { "error", "failed" }
    });
    #endif
    }
    }
     
  7. Schabbs

    Schabbs

    Joined:
    Aug 14, 2015
    Posts:
    3
    We just noticed that the issue seems to only occur in editor. If we make a build and run it on an android device everything works as expected.
     
    Unity_Quinn and Bodin like this.
  8. DucaDiMonteSberna

    DucaDiMonteSberna

    Joined:
    Jan 18, 2018
    Posts:
    34
    In my case error is presnt in both the editor and on build
     
  9. DucaDiMonteSberna

    DucaDiMonteSberna

    Joined:
    Jan 18, 2018
    Posts:
    34
    Update: updated to 3.7.5 and the problem still persist
     
    Bodin likes this.
  10. LIU_Hanyang96

    LIU_Hanyang96

    Unity Technologies

    Joined:
    Jul 12, 2021
    Posts:
    69
    Hi,

    For your problem, I have tested with UnityAds SDK 3.7.5. May I know whether this happened each time? It works well on my side.
    Here are some codes you may need to pay attention to:
    Advertisement.Initialize(androidID, testMode, true); //The last true is for EnablePerPlacement. Without it, you may load ads failed.
    Advertisement.Show(mySurfacingId2, this); //You need to set up listener to catch the callback.


    I hope this will help.
     
    APZ_legit likes this.
  11. DucaDiMonteSberna

    DucaDiMonteSberna

    Joined:
    Jan 18, 2018
    Posts:
    34
    the problem seems fixed in the builld after re-enabling EnablePerPlacement (not sure why one would turn it off), but it still persist in the editor. It's a bit annoying because I have to build every time I have some changes I want to verify
     
  12. Termobudka

    Termobudka

    Joined:
    Jan 30, 2018
    Posts:
    7
    i have the same bug. 2020.3.14 and sdk 3.7.5. "OnUnityAdsShowComplete" dont work.
    There may be something wrong with the test ads. Instead of a video, it shows a static image. Perhaps because of this, it does not work.
    OnUnityAdsShowStart - work
    OnUnityAdsDidStart - work
    OnUnityAdsDidFinish - work.
     
    Last edited: Aug 16, 2021
  13. LIU_Hanyang96

    LIU_Hanyang96

    Unity Technologies

    Joined:
    Jul 12, 2021
    Posts:
    69
    Hi,

    May I confirm with you whether you use "IUnityAdsShowListener" interface, and set it to your SDK(Advertisement.Show(placementId, this); )?
     
  14. Termobudka

    Termobudka

    Joined:
    Jan 30, 2018
    Posts:
    7
    init.PNG
    show.PNG
    adsshow.PNG
    finish.PNG
     
    Last edited: Aug 17, 2021
  15. LIU_Hanyang96

    LIU_Hanyang96

    Unity Technologies

    Joined:
    Jul 12, 2021
    Posts:
    69
    Termobudka likes this.
  16. Termobudka

    Termobudka

    Joined:
    Jan 30, 2018
    Posts:
    7
    I thought so, that the test ad in the editor, does not call OnComplete. in the mobile all work good.
    it would be nice if the editor also worked.
     
  17. winnie_88

    winnie_88

    Joined:
    Feb 28, 2014
    Posts:
    3
    I also have the same problem on Unity 2020.3.14f1 and SDK 3.7.5, wheter I run it from the editor or my Android device, the OnUnityAdsShowComplete isn't triggering.
     
  18. LIU_Hanyang96

    LIU_Hanyang96

    Unity Technologies

    Joined:
    Jul 12, 2021
    Posts:
    69
    Hi Winnie,

    May I check whether you use the "IUnityAdsShowListener" interface and set it to your SDK(Advertisement.Show(placementId, this); )? Only this setting will trigger the "OnUnityAdsShowComplete". What's more, it will not be triggered in the Editor, but only on the real phone.

    If you still meet this problem, may you send us some sample codes of your project?
     
    winnie_88 likes this.
  19. winnie_88

    winnie_88

    Joined:
    Feb 28, 2014
    Posts:
    3
    Yes of course, thanks a lot LIU. I'm loading the Ad through the ShowAd() method with the continueButton, it's linked via the Editor in case you require that information.


    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Advertisements;
    3. using UnityEngine.SceneManagement;
    4. using UnityEngine.UI;
    5.  
    6. public class RewardedAd : MonoBehaviour, IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener
    7. {
    8.  
    9. #if UNITY_IOS
    10.     private string gameId = "4268458";
    11. #elif UNITY_ANDROID
    12.     private string gameId = "4268459";
    13. #endif
    14.  
    15.     bool testMode = true;
    16.  
    17.     private string adUnitId;
    18.     public GameMaster gm;
    19.     public Button continueButton;
    20.  
    21.     void Start()
    22.     {
    23.         adUnitId = "Rewarded_Android";
    24.  
    25.         Advertisement.Initialize(gameId, testMode, true, this);
    26.     }
    27.  
    28.     public void LoadAd()
    29.     {
    30.         Debug.Log("Loading Ad");
    31.         Advertisement.Load(adUnitId, this);
    32.     }
    33.  
    34.     public void ShowAd()
    35.     {
    36.         Debug.Log("Showing Ad");
    37.         Advertisement.Show(adUnitId, this);
    38.     }
    39.     public void OnInitializationComplete()
    40.     {
    41.         Debug.Log("Unity Ads initialization complete.");
    42.         LoadAd();
    43.     }
    44.  
    45.     public void OnInitializationFailed(UnityAdsInitializationError error, string message)
    46.     {
    47.         Debug.Log($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
    48.         SceneManager.LoadScene(SceneManager.GetActiveScene().name, LoadSceneMode.Single);
    49.     }
    50.  
    51.     // Implement Load Listener and Show Listener interface methods:
    52.     public void OnUnityAdsAdLoaded(string adUnitId)
    53.     {
    54.         Debug.Log("Ad Loaded successfully");
    55.         // Optionally execute code if the Ad Unit successfully loads content.
    56.         continueButton.interactable = true;
    57.     }
    58.  
    59.     public void OnUnityAdsFailedToLoad(string adUnitId, UnityAdsLoadError error, string message)
    60.     {
    61.      
    62.         Debug.Log($"Error loading Ad Unit: {adUnitId} - {error.ToString()} - {message}");
    63.         // Optionally execute code if the Ad Unit fails to load, such as attempting to try again.
    64.         SceneManager.LoadScene(SceneManager.GetActiveScene().name, LoadSceneMode.Single);
    65.     }
    66.  
    67.     public void OnUnityAdsShowFailure(string adUnitId, UnityAdsShowError error, string message)
    68.     {
    69.         Debug.Log($"Error showing Ad Unit {adUnitId}: {error.ToString()} - {message}");
    70.         // Optionally execite code if the Ad Unit fails to show, such as loading another ad.
    71.         SceneManager.LoadScene(SceneManager.GetActiveScene().name, LoadSceneMode.Single);
    72.     }
    73.  
    74.     public void OnUnityAdsShowStart(string adUnitId) {
    75.         Debug.Log("OnUnityAdsShowStart");
    76.     }
    77.     public void OnUnityAdsShowClick(string adUnitId) {
    78.         Debug.Log("OnUnityAdsShowClick");
    79.     }
    80.     public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState) {
    81.         Debug.Log("OnUnityAdsShowComplete");
    82.         //gm.HideContinueScreen();
    83.         //continueButton.GetComponentInChildren<Text>().text = "LET'S GO";
    84.         if (adUnitId.Equals("Rewarded_Android") && showCompletionState == UnityAdsShowCompletionState.COMPLETED)
    85.         {
    86.             Debug.Log("Completed Rewarded Ad");
    87.         }
    88.         Advertisement.Load(adUnitId);
    89.     }
    90.  
    91.     private void OnDestroy()
    92.     {
    93.      
    94.     }
    95. }
     
    Last edited: Aug 19, 2021
  20. D00MX

    D00MX

    Joined:
    Feb 2, 2019
    Posts:
    2
    Hello everyone, I am following the latest implementation and I am having the same problem "Fake" ad like @LIU_Hanyang96 mentioned is fired in the editor but no response from listener. On device Ad is not shown at all and when I check logs through logcat I see this everytime I try to show ad:

    java.lang.ClassNotFoundException: com.unity3d.ads.IUnityAdsShowListener
    08-19 09:43:14.667 24240 24292 E Unity : at java.lang.Class.classForName(Native Method)
    08-19 09:43:14.667 24240 24292 E Unity : at java.lang.Class.forName(Class.java:454)
    08-19 09:43:14.667 24240 24292 E Unity : at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
    08-19 09:43:14.667 24240 24292 E Unity : at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0)
    08-19 09:43:14.667 24240 24292 E Unity : at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95)
    08-19 09:43:14.667 24240 24292 E Unity : at android.os.Handler.dispatchMessage(Handler.java:103)
    08-19 09:43:14.667 24240 24292 E Unity : at android.os.Looper.loop(Looper.java:224)
    08-19 09:43:14.667 24240 24292 E Unity : at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)
    08-19 09:43:14.667 24240 24292 E Unity : Caused by: java.lang.ClassNotFoundException: com.unity3d.ads.IUnityAdsShowListener
    08-19 09:43:14.667 24240 24292 E Unity : ... 8 more
    08-19 09:43:14.667 24240 24292 E Unity : at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0
    08-19 09:43:14.667 24240 24292 E Unity : at UnityEngine.AndroidJNISafe.FindClass (System.String name) [0x00000] in <00000000000000000000000000000000>:0
    08-19 09:43:14.667 24240 24292 E Unity : at UnityEngine.AndroidJavaClass._AndroidJavaClass (System.String className) [0x00000] in <000​

    My code for Ad is here:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Advertisements;
    3.  
    4. public class AdManager : MonoBehaviour, IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener
    5. {
    6.     [Header("References")]
    7.     [SerializeField] EventManager m_EventManager;
    8.     [SerializeField] InventoryManager m_InventoryManager;
    9.  
    10.     [Header("Initialize Ads")]
    11.     [SerializeField] string _androidGameId;
    12.     [SerializeField] string _iOsGameId;
    13.     [SerializeField] bool _testMode = true;
    14.     [SerializeField] bool _enablePerPlacementMode = true;
    15.     private string _gameId;
    16.  
    17.     [Header("Rewarded video Ad")]
    18.     [SerializeField] string _androidAdUnitId = "Rewarded_Android";
    19.     [SerializeField] string _iOsAdUnitId = "Rewarded_iOS";
    20.     string _adUnitId;
    21.  
    22.     public bool videoAdReady;
    23.  
    24.     void Awake()
    25.     {
    26.         InitializeAds();
    27.  
    28.         // Get the Ad Unit ID for the current platform:
    29.         _adUnitId = (Application.platform == RuntimePlatform.IPhonePlayer)
    30.             ? _iOsAdUnitId
    31.             : _androidAdUnitId;
    32.     }
    33.  
    34.     public void InitializeAds()
    35.     {
    36.         _gameId = (Application.platform == RuntimePlatform.IPhonePlayer)
    37.             ? _iOsGameId
    38.             : _androidGameId;
    39.         Advertisement.Initialize(_gameId, _testMode, _enablePerPlacementMode, this);
    40.     }
    41.  
    42.     public void OnInitializationComplete()
    43.     {
    44.         LoadAd();
    45.         Debug.Log("Unity Ads initialization complete.");
    46.     }
    47.  
    48.     public void OnInitializationFailed(UnityAdsInitializationError error, string message)
    49.     {
    50.         Debug.Log($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
    51.     }
    52.  
    53.     // Load content to the Ad Unit:
    54.     public void LoadAd()
    55.     {
    56.         // IMPORTANT! Only load content AFTER initialization (in this example, initialization is handled in a different script).
    57.         Debug.Log("Loading Ad: " + _adUnitId);
    58.         Advertisement.Load(_adUnitId, this);
    59.     }
    60.  
    61.     // If the ad successfully loads, add a listener to the button and enable it:
    62.     public void OnUnityAdsAdLoaded(string adUnitId)
    63.     {
    64.         Debug.Log("Ad Loaded: " + adUnitId);
    65.         videoAdReady = true;
    66.     }
    67.  
    68.  
    69.     public void ShowAd()
    70.     {
    71.        
    72.         Advertisement.Show(_adUnitId, this);
    73.     }
    74.  
    75.  
    76.     public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState)
    77.     {
    78.         if (adUnitId.Equals(_adUnitId) && showCompletionState.Equals(UnityAdsShowCompletionState.COMPLETED))
    79.         {
    80.             Debug.Log("Unity Ads Rewarded Ad Completed");
    81.             // Grant a reward.
    82.  
    83.             if(m_EventManager.doubleStarsRewardedVideo == true)
    84.             {
    85.                 m_EventManager.doubleStarsRewardedVideo = false;
    86.                 m_EventManager.StarsDoubled();
    87.             }
    88.  
    89.             if (m_EventManager.secondLifeRewardedVideo == true)
    90.             {
    91.                 m_EventManager.secondLifeRewardedVideo = false;
    92.                 m_EventManager.SecondLife();
    93.             }
    94.  
    95.             if (m_InventoryManager.AddCurrencyRewardedVideo == true)
    96.             {
    97.                 m_InventoryManager.AddCurrencyRewardedVideo = false;
    98.                 m_InventoryManager.AddCurrencyVideoAd();
    99.             }
    100.  
    101.  
    102.             // Load another ad:
    103.             Advertisement.Load(_adUnitId, this);
    104.         }
    105.     }
    106.  
    107.     // Implement Load and Show Listener error callbacks:
    108.     public void OnUnityAdsFailedToLoad(string adUnitId, UnityAdsLoadError error, string message)
    109.     {
    110.         Debug.Log($"Error loading Ad Unit {adUnitId}: {error.ToString()} - {message}");
    111.         // Use the error details to determine whether to try to load another ad.
    112.     }
    113.  
    114.     public void OnUnityAdsShowFailure(string adUnitId, UnityAdsShowError error, string message)
    115.     {
    116.         Debug.Log($"Error showing Ad Unit {adUnitId}: {error.ToString()} - {message}");
    117.         // Use the error details to determine whether to try to load another ad.
    118.     }
    119.  
    120.     public void OnUnityAdsShowStart(string adUnitId) { }
    121.     public void OnUnityAdsShowClick(string adUnitId) { }
    122. }
    Thank you in advance if someone could help me how to resolve this.
     
    winnie_88 likes this.
  21. LIU_Hanyang96

    LIU_Hanyang96

    Unity Technologies

    Joined:
    Jul 12, 2021
    Posts:
    69
    Hi,

    May you set the testMode as false? Also, may I know whether your "adUnitId" is "Rewarded_Android"? You need to test the real ads with real devices, and only real ads can trigger complete callbacks.
     
  22. LIU_Hanyang96

    LIU_Hanyang96

    Unity Technologies

    Joined:
    Jul 12, 2021
    Posts:
    69
    Hi,

    I think your problem is caused by the library missing as you package it to the Android platform. May you check your building settings? Or you can try to re-install the SDK package. If you still cannot solve this, may you send us the details of your settings?
     
  23. ShockFactor

    ShockFactor

    Joined:
    Sep 30, 2015
    Posts:
    8
    Can we request that functionality be re-added for the editor? Please? Building to a device slows down iteration dramatically. Also, Using the older Ad calls worked fine in the editor.
     
    D12294, D00MX and winnie_88 like this.
  24. winnie_88

    winnie_88

    Joined:
    Feb 28, 2014
    Posts:
    3
    I agree. I mean, if we need to set the testMode to false to check callbacks and build everytime we need to test our code, we could be flagged for fraud and iterations are really slow
     
    D12294 and D00MX like this.
  25. Samhay

    Samhay

    Joined:
    Mar 23, 2011
    Posts:
    5
    Not sure if this is related to same issue. We have unity ads as mediation with admob and for some ads it does not fire rewarded event on android. After some testing it seems that it is playable ads on android that wont trigger reward event on admob side.

    Did some logcat research and for non playable rewarded ads there is unity ads logs for started, first quartile, mid, third quartile and finished. For playables all other steps are logged but not finished, so it might be that finished is never called and that's why admob will not fire reward event.

    Of course this can be separate issue and/or issue with mediation adapter but there seems to be similarities so decided to share while stumbled upon this thread while looking for solution.
     
    D12294 likes this.
  26. krupps

    krupps

    Joined:
    Oct 17, 2017
    Posts:
    109
    @LIU_Hanyang96 This makes it really hard to test. Is there a way to trap(handle) the close button, so we can simulate this in the editor before deployment?

    My Ads work fine in mobile, but deploying to iOS takes a while. It would be nice if we could trap the close button in test mode.
     
    D12294 likes this.
  27. unity_TkvnlsDCpw-owg

    unity_TkvnlsDCpw-owg

    Joined:
    Jul 16, 2020
    Posts:
    12
    I am having the exact same problem. What I dont like - the issue is causing lot on anxiety whether everything will work properly on Build or not. In the Editor the Reward is not getting granted like before if the bool TestMode is true.

    Since its a fake ad - UnityAdsShowCompletionState.COMPLETED is never attained. & hence I have resigned to the fact that this issue is unsolvable till one builds an actual .apk to test.
     
    Last edited: Aug 31, 2021
    D12294 and D00MX like this.
  28. Zepir

    Zepir

    Joined:
    Dec 16, 2016
    Posts:
    15
    I'm probably going to use the old method until they fix all this stuff, testing the Ads in the editor with the new method (3.7+) should be easier. OnUnityAdsShowComplete should trigger in the editor like before to allow much faster testing. I hope they're already aware of this.
     
    D12294 and D00MX like this.
  29. D00MX

    D00MX

    Joined:
    Feb 2, 2019
    Posts:
    2
    I agree. I am forced to roll back until this is resolved. Please developers make testing in Unity available again. It is the reason I left other providers for Unity Ads only to find that new version is not working properly.
     
    D12294 likes this.
  30. krupps

    krupps

    Joined:
    Oct 17, 2017
    Posts:
    109
    What I ended up doing is I have an Ad prefab window and I show 2 buttons in test mode "Simlulate Skipped Video" and "Simulate Completed Video" and just send the appropriate enum value. This works, but is a really ugly code smell.

    Not sure why Unity isn't making this a priority
     
unityunity