Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Ads not working in fresh project

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

  1. SplitShard


    Aug 27, 2016
    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;
    5. public class AdManager : MonoBehaviour {
    7.     void Start() {
    8.         StartCoroutine(ShowAdWhenReady());
    9.     }
    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.     }
    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. }
    I can see coroutine start, but it never exits the while loop, meaning that the
    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


    Unity Technologies

    Oct 13, 2016
    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. SplitShard


    Aug 27, 2016
    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.
  4. aniketandy141


    Dec 29, 2018
    @DenisasK i upgraded to ads to 3.2.0 but got a new problem

    private void HandleAdResult(ShowResult result)
    switch (result)
    case ShowResult.Finished:
    case ShowResult.Skipped:
    Debug.Log("player didnt watch the ad");
    case ShowResult.Failed:
    Debug.Log("No Internet");
    result.finished works as required but when i disconnect my internet connection showresult.failed dosent work forget the coroutine i dont even get the debug message of no internet, my unity version is 2019.2.6f1

    Edit: it works when i disconnect internet it means ad is not ready so i needed to check if(!Advertisement.IsReady()) sorry for disturbing as i was stuck for 5 days in this
    Last edited: Oct 5, 2019