Search Unity

Unity Ads error and not showing ads on release

Discussion in 'Unity Ads' started by ShirninDeveloperTeam, Aug 23, 2019.

  1. ShirninDeveloperTeam

    ShirninDeveloperTeam

    Joined:
    Jul 25, 2018
    Posts:
    3
    When I start the project, the following appears in the console:

    ArgumentException: An item with the same key has already been added. Key: video
    System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <1f0c1ef1ad524c38bbc5536809c46b48>:0)
    System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <1f0c1ef1ad524c38bbc5536809c46b48>:0)
    UnityEngine.Advertisements.Platform+<Initialize>c__AnonStorey1.<>m__2 (UnityEngine.Advertisements.CallbackExecutor execute) (at <528e263cfc394d2a83ef2b58915acc90>:0)
    UnityEngine.Advertisements.CallbackExecutor.Update () (at <528e263cfc394d2a83ef2b58915acc90>:0)

    and see it

    (alt. img link: http://joxi.ru/EA4w9bVco1pvx2)

    services window:

    (alt. img link: http://joxi.ru/Vm6wv3Vc4lv3k2)

    packages manager window

    (alt. img link: http://joxi.ru/Dr8wv9VcoaMDzA)

    I installed Unity Monetification 3.2.0 from assets

    script:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Advertisements;
    5. using UnityEngine.SceneManagement;
    6.  
    7. public class UnityAdsScript : MonoBehaviour
    8. {
    9. #if UNITY_ANDROID
    10.     public const string gameId = "0*****1";
    11. #elif UNITY_IOS
    12.     public const string gameId = "0*****2";
    13. #elif UNITY_EDITOR
    14.     public const string gameId = "0123456";
    15. #endif
    16.  
    17.     private string bannerPlacement = "MainMenu";
    18.     private bool testMode = false;
    19.  
    20.     public void Start()
    21.     {
    22.         Advertisement.Initialize(gameId, testMode);
    23.         NoHide();
    24.     }
    25.  
    26.     public void NoHide()
    27.     {
    28.         StartCoroutine(ShowBannerWhenReady());
    29.     }
    30.  
    31.     public void Hide()
    32.     {
    33.         Advertisement.Banner.Hide();
    34.     }
    35.  
    36.     IEnumerator ShowBannerWhenReady()
    37.     {
    38.         while (!Advertisement.IsReady("MainMenu"))
    39.         {
    40.             yield return new WaitForSeconds(0.5f);
    41.         }
    42.         Advertisement.Banner.Show(bannerPlacement);
    43.     }
    44. }
     
  2. ShirninDeveloperTeam

    ShirninDeveloperTeam

    Joined:
    Jul 25, 2018
    Posts:
    3
  3. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,277
    @ShirninDeveloperTeam

    Have you tried removing the package and re-installing it?

    I haven't seen that error before, so I'm wondering if the asset package just ended up in a weird state while importing.

    Let me know if that doesn't resolve the issue and we'll try to reproduce it on our end.
     
  4. ShirninDeveloperTeam

    ShirninDeveloperTeam

    Joined:
    Jul 25, 2018
    Posts:
    3
    Yes, I deleted it and reinstalled it, tried many options, but I still got this error.

    Even in the console, this was displayed:

     
  5. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,277
    @ShirninDeveloperTeam

    I was able to reproduce this error by including the Ads script twice in the scene, essentially initializing the SDK multiple times. If you right-click on your script, you can select "Find References in Scene" to find all the places where the script is included in the scene.