[SOLVED] Ads are not working in Editor or Android

Hi,

I am trying to implement a rewarded Ad like this:

void Start ()
{
    if (Monetization.isSupported)
    {
        Monetization.Initialize(gameId, testMode);
    }
}

public void ShowAd() //Called via Button Click
{
    StartCoroutine(WaitForAd());
}

IEnumerator WaitForAd()
{
    //STUCK HERE, ALWAYS FALSE
    while (!Monetization.IsReady(placementId))
    {
        yield return null;
    }

    ShowAdPlacementContent ad = null;
    ad = Monetization.GetPlacementContent(placementId) as ShowAdPlacementContent;

    if (ad != null)
    {
        ad.Show(HandleShowResult);
    }
}

In the Unity Editor (2018.4.0f1) the Monetization.IsReady(placementId) always returns false. On Android nothing happens either.

I tried it this way:

ShowAdCallbacks options = new ShowAdCallbacks();
options.finishCallback = HandleShowResult;
ShowAdPlacementContent ad = Monetization.GetPlacementContent(placementId) as ShowAdPlacementContent;

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.

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 How To - Capturing Device Logs on Android

Hi Jeff,

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