Search Unity

Bug Unity 2022.2 Advertisement Legacy weird Bug

Discussion in 'Unity Ads & User Acquisition' started by RenOli, May 24, 2023.

  1. RenOli

    RenOli

    Joined:
    Jan 23, 2013
    Posts:
    102
    Hi, I am almost done with the implementation of the Unity Ads in my project,
    I can't add the game ID here, it doesn't allow me to edit the text field, which I am not sure is the reason of the error I am getting.
    upload_2023-5-23_23-5-50.png

    I am adding the ID as a string in my script for the initialize.
    I am getting INVALID_ARGUMENT when trying to play the Rewarded ad. I have no idea why, I triple checked every string. Even on Test mode it is not playing.
    In Editor the Fake Ad screen does happen.

    I am assuming this is the reason.

    Weird thing is that BANNER is working!

    Any idea?

    (I was using the latest mediation, but Iron Source support is the worst thing I've ever seen and lots of errors were happening)
     
  2. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    626
    You may have configured the wrong placement ID. Please note that the placement IDs corresponding to each Game ID may be different. Please check the Unity dashboard to ensure that the Game ID and placement IDs you are using are correct.
     
  3. RenOli

    RenOli

    Joined:
    Jan 23, 2013
    Posts:
    102
    Yeah, everything is set up as in the ADS Service
    I am setting up the strings on Start, for IOS and the ones for Android
    Code (CSharp):
    1. #if UNITY_EDITOR
    2.             testMode = true;
    3. #endif
    4.  
    5. #if UNITY_ANDROID
    6.         testMode = false;
    7.         app_key = "******9";
    8.         bannerID = "Banner_Android";
    9.         rewardedDouble = "Rewarded_Android";
    10.         rewardExtraLife = "Rewarded_ExtraLife_Android";
    11.         skipAd = "Interstitial_Android";
    12. #endif
    13. #if UNITY_IOS
    14.         testMode = false;
    15.         app_key = "******8";
    16.         bannerID = "Banner_iOS";
    17.         rewardedDouble = "Rewarded_iOS";
    18.         rewardExtraLife = "Rewarded_ExtraLife_IOS";
    19.         skipAd = "Interstitial_iOS";
    20.          
    21. #endif
    22.         Advertisement.Initialize(app_key, testMode,this);
    I just click on copy to clipboard on the website and paste it
     
  4. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    626
    Can you provide device logs from SDK initialization so we can investigate further?
     
  5. RenOli

    RenOli

    Joined:
    Jan 23, 2013
    Posts:
    102
    I found this on the logcat

    Code (CSharp):
    1. "com.unity3d.services.core.api.Sdk.logError() (line:76) :: Show invocation failed: Placement Interstitial_Android must be Loaded before calling Show: https://docs.unity.com/ads/UnityAPI.html#Load
    2. 05-24 05:05:30.154 27508 27536 E Unity   : Failed to show ad: Placement Interstitial_Android must be Loaded before calling Show: https://docs.unity.com/ads/UnityAPI.html#Load, error: INVALID_ARGUMENT"
    I am using the latest Ad version on the Package Manager for Unity 2022.2

    Here is my code! The Object is right at the first loading scene, it is never called again

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Advertisements;
    3.  
    4. public class AdsManager : MonoBehaviour, IUnityAdsShowListener, IUnityAdsInitializationListener
    5. {
    6.     public static AdsManager adsManager;
    7.     string app_key = "";
    8.  
    9.     string bannerID = "";
    10.     string rewardedDouble = "";
    11.     string rewardExtraLife = "";
    12.     string skipAd = "";
    13.     bool testMode;
    14.  
    15.     bool adsAreRunning;
    16.     void Start()
    17.     {
    18.         if (AdsManager.adsManager == null)
    19.         {
    20.  
    21.             DontDestroyOnLoad(gameObject);
    22.             AdsManager.adsManager = this;
    23.         }
    24.         else
    25.         {
    26.             Destroy(gameObject);
    27.             return;
    28.         }
    29.  
    30. #if UNITY_EDITOR
    31.         testMode = true;
    32. #endif
    33.  
    34. #if UNITY_ANDROID
    35.         testMode = false;
    36.         app_key = "*******";
    37.         bannerID = "Banner_Android";
    38.         rewardedDouble = "Rewarded_Android";
    39.         rewardExtraLife = "Rewarded_ExtraLife_Android";
    40.         skipAd = "Interstitial_Android";
    41. #endif
    42. #if UNITY_IOS
    43.         testMode = false;
    44.         app_key = "******";
    45.         bannerID = "Banner_iOS";
    46.         rewardedDouble = "Rewarded_iOS";
    47.         rewardExtraLife = "Rewarded_ExtraLife_IOS";
    48.         skipAd = "Interstitial_iOS";
    49.            
    50. #endif
    51.         Advertisement.Initialize(app_key, testMode, this);
    52.  
    53.     }
    54.  
    55.     public void OnInitializationFailed(UnityAdsInitializationError error, string message)
    56.     {
    57.         Debug.Log("Unity Ads initialization falied.");
    58.         adsAreRunning = false;
    59.         CancelInvoke("TryInitializeAgain");
    60.         Invoke("TryInitializeAgain", 1);
    61.     }
    62.  
    63.     private void TryInitializeAgain()
    64.     {
    65.         Advertisement.Initialize(app_key, testMode);
    66.     }
    67.  
    68.     public void OnInitializationComplete()
    69.     {
    70.         Debug.Log("Unity Ads initialization complete.");
    71.  
    72.     }
    73.  
    74.     public void OnUnityAdsShowFailure(UnityAdsInitializationError error, string message)
    75.     {
    76.         Debug.Log($"Unity Ads Initialization Failed: {error} - {message}");
    77.  
    78.     }
    79.  
    80.     public void LoadBanner()
    81.     {
    82.         print("LOADING BANNER");
    83.         if (Advertisement.isInitialized)
    84.         {
    85.             Advertisement.Banner.SetPosition(BannerPosition.BOTTOM_CENTER);
    86.             Advertisement.Banner.Show(bannerID);
    87.  
    88.             print("LOADING BANNER DONE");
    89.         }
    90.     }
    91.  
    92.     public void DestroyBanner()
    93.     {
    94.         if (Advertisement.isInitialized)
    95.         {
    96.             Advertisement.Banner.Hide(true);
    97.         }
    98.  
    99.     }
    100.  
    101.  
    102.     public void ShowRewardedAd()
    103.     {
    104.         print("LOADING REWARDED");
    105.         if (Advertisement.isInitialized)
    106.         {
    107.             Advertisement.Show(rewardedDouble, this);
    108.         }
    109.     }
    110.  
    111.     public void ShowRewardedAdForLife()
    112.     {
    113.         print("LOADING REWARDED FOR LIFE");
    114.         if (Advertisement.isInitialized)
    115.         {
    116.             Advertisement.Show(rewardExtraLife, this);
    117.         }
    118.     }
    119.  
    120.  
    121.     public void OnUnityAdsShowComplete(string placementId, UnityAdsShowCompletionState showCompletionState)
    122.     {
    123.  
    124.         if (placementId.Equals(rewardedDouble) && showCompletionState == UnityAdsShowCompletionState.COMPLETED)
    125.         {
    126.             Debug.Log("Ad completed, reward the player " + rewardedDouble);
    127.             FinalScoreManager.finalScoreManager.DoubleScoreWatchedAd();
    128.  
    129.         }
    130.         else if (placementId.Equals(rewardExtraLife) && showCompletionState == UnityAdsShowCompletionState.COMPLETED)
    131.         {
    132.             Debug.Log("Ad completed, reward the player " + rewardedDouble);
    133.             MainMenuManager.mainMenu.PlayAdsForLifeSuccess();
    134.  
    135.         }
    136.         else if (placementId.Equals(skipAd))
    137.         {
    138.  
    139.         }
    140.     }
    141.  
    142.     public void OnUnityAdsShowFailure(string placementId, UnityAdsShowError error, string message)
    143.     {
    144.         Debug.LogError($"Failed to show ad: {message}, error: {error}");
    145.         if (placementId.Equals(rewardedDouble))
    146.         {
    147.             FinalScoreManager.finalScoreManager.AdErrorMessage("ERROR: " + error + "");
    148.  
    149.         }
    150.         else if (placementId.Equals(rewardExtraLife))
    151.         {
    152.             MainMenuManager.mainMenu.PlayAdsForLifeFailed(error + "");
    153.  
    154.         }
    155.         else if (placementId.Equals(skipAd))
    156.         {
    157.             //MainMenuManager.mainMenu.PlayAdsForLifeFailed(error + "");
    158.  
    159.         }
    160.         if (!Advertisement.isInitialized)
    161.         {
    162.             Advertisement.Initialize(app_key, testMode, this);
    163.         }
    164.     }
    165.  
    166.     public void OnUnityAdsShowStart(string placementId)
    167.     {
    168.         Debug.Log("Ad started " + placementId);
    169.     }
    170.  
    171.     public void OnUnityAdsShowClick(string placementId)
    172.     {
    173.         Debug.Log("Ad clicked " + placementId);
    174.     }
    175.  
    176.     public void ShowSkippableAd()
    177.     {
    178.         Advertisement.Show(skipAd, this);
    179.     }
    180.  
    181. }
    182.  
     
  6. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    626
  7. RenOli

    RenOli

    Joined:
    Jan 23, 2013
    Posts:
    102
    Ohh, PERFECT. That was exactly that. I missed that part.
    Thank you so much.
     
    SamOYUnity3D likes this.