Search Unity

Ads not working in fresh project

Discussion in 'Unity Ads' started by Shard-, Apr 4, 2019.

  1. Shard-

    Shard-

    Joined:
    Aug 27, 2016
    Posts:
    3
    I'm using Unity 2018.3.9f1 (Personal) to create a simple test project to test how Unity Ads work.
    I do the following steps:

    1) Switch platform to Android from Build Settings
    2) Go into Services and enable ADS
    3) Enable test mode within ADS tab
    4) Enable built-in Ads extension
    5) Create a super simple script to start the default rewardedVideo once it is ready

    but nothing happens. When game is run in editor I get the following log in console:
    Code (CSharp):
    1. UnityAdsEditor: Initialize(XXXXXXX, True);
    2. UnityEditor.Advertisements.UnityAdsEditor:EditorOnLoad()
    I can see that XXXXXXX is the correct game id, that matches the one in dashboard. So it seems to initialize the ads successfully.

    Here is the simple script that tries to show an ad:

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using UnityEngine.Advertisements;
    4.  
    5. public class AdManager : MonoBehaviour {
    6.  
    7.     void Start() {
    8.         StartCoroutine(ShowAdWhenReady());
    9.     }
    10.  
    11.     IEnumerator ShowAdWhenReady() {
    12.         Debug.Log("In coroutine");
    13.         while (!Advertisement.IsReady("rewardedVideo")) {
    14.             yield return null;
    15.         }
    16.         var options = new ShowOptions { resultCallback = HandleShowResult };
    17.         Advertisement.Show("rewardedVideo", options);
    18.     }
    19.  
    20.     private void HandleShowResult(ShowResult result) {
    21.         switch (result) {
    22.             case ShowResult.Finished:
    23.                 Debug.Log("The ad was successfully shown.");
    24.                 //
    25.                 // YOUR CODE TO REWARD THE GAMER
    26.                 // Give coins etc.
    27.                 break;
    28.             case ShowResult.Skipped:
    29.                 Debug.Log("The ad was skipped before reaching the end.");
    30.                 break;
    31.             case ShowResult.Failed:
    32.                 Debug.LogError("The ad failed to be shown.");
    33.                 break;
    34.         }
    35.     }
    36. }
    37.  
    I can see coroutine start, but it never exits the while loop, meaning that the
    !Advertisement.IsReady("rewardedVideo")
    is always true. In other words ad is never ready.

    I have created several fresh projects and tried all kinds of things, like creating an ad and not using one of the pre-created ones. I have tried setting Enable built-in Ads extension to false and using the SDK from Asset Store. I have tried manually initializing the Advertisements with no luck. It drives me crazy how simple every tutorial makes it look, yet someone with extensive programming and unity knowledge can't get this to work.

    Any help is appreciated!
     
    Last edited: Apr 4, 2019
  2. DenisasK

    DenisasK

    Unity Technologies

    Joined:
    Oct 13, 2016
    Posts:
    89
    Hello @Shard- ,
    If you want to init Unity Ads manually, you can use Asset Store package but the built-in Ads extension must but set to false, and Advertisement package removed from Package Manager.
    If you want to try auto-init functionality. You must set the built-in Ads extension to true, I would recommend updating the Advertisement package to 3.0.3 from Package Manager. In case if you will encounter a bug, please, set the built-in Ads extension to false and try to init it manually (Package Manager). Please, do not mix implementations.
     
  3. Shard-

    Shard-

    Joined:
    Aug 27, 2016
    Posts:
    3
    Yeah that was exactly how I did it, disabled everything in one before trying the other. Was never mixing them together. But Package Manager upgrade of Ads to 3.0.3 is something I had not yet done, and that seemed to have fixed it Such a simple step, but not mentioned anywhere. Hopefully this post will help others like me in the future. Thank you!
     
    DenisasK likes this.