Search Unity

[SOLVED] Ads are not working in Editor or Android

Discussion in 'Unity Ads & User Acquisition' started by Irrgeist, May 17, 2019.

  1. Irrgeist

    Irrgeist

    Joined:
    Jul 9, 2015
    Posts:
    28
    Hi,

    I am trying to implement a rewarded Ad like this:

    Code (CSharp):
    1. void Start ()
    2. {
    3.     if (Monetization.isSupported)
    4.     {
    5.         Monetization.Initialize(gameId, testMode);
    6.     }
    7. }
    8.  
    9. public void ShowAd() //Called via Button Click
    10. {
    11.     StartCoroutine(WaitForAd());
    12. }
    13.  
    14. IEnumerator WaitForAd()
    15. {
    16.     //STUCK HERE, ALWAYS FALSE
    17.     while (!Monetization.IsReady(placementId))
    18.     {
    19.         yield return null;
    20.     }
    21.  
    22.     ShowAdPlacementContent ad = null;
    23.     ad = Monetization.GetPlacementContent(placementId) as ShowAdPlacementContent;
    24.  
    25.     if (ad != null)
    26.     {
    27.         ad.Show(HandleShowResult);
    28.     }
    29. }
    In the Unity Editor (2018.4.0f1) the Monetization.IsReady(placementId) always returns false. On Android nothing happens either.

    I tried it this way:
    Code (CSharp):
    1. ShowAdCallbacks options = new ShowAdCallbacks();
    2. options.finishCallback = HandleShowResult;
    3. ShowAdPlacementContent ad = Monetization.GetPlacementContent(placementId) as ShowAdPlacementContent;
    4.  
    5. ad.Show(options);
    This works in the Editor, I get a test ad from Unity, but on Android I get a NullPointerException this way. I double checked the game ID. It should be this one:


    What could be the problem?! The placementID is the default "rewardedVideo".

    I deactivated the built-In Unity Service and added the Unity Monetization 3.0.3 from the Asset store.

    If this will not work I think I have to switch to Google Ads and see if this works better for the game.
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    That isn't the gameID that you show in the screenshot, that is the ProjectID. The gameID is under Settings/ProjectSettings on the Operate tab for the project. You'll see separate gameIDs for Android and iOS. Debug.Log it to ensure the runtime values are the expected values. You're not showing where you declare gameID for example. Is it a public variable, set in the Inspector? The Debug.Log output will show in the device logs too https://forum.unity.com/threads/how-to-capturing-device-logs-on-android.528680/

     
    Last edited: May 17, 2019
  3. Irrgeist

    Irrgeist

    Joined:
    Jul 9, 2015
    Posts:
    28
    Hi Jeff,

    wow that was super stupid of me...now it's working ... guess I need more sleep haha. Thank you very much! :)