Search Unity

Ads not working in fresh project

Discussion in 'Unity Ads & User Acquisition' started by CaptainOtter, Apr 4, 2019.

Thread Status:
Not open for further replies.
  1. CaptainOtter

    CaptainOtter

    Joined:
    Aug 27, 2016
    Posts:
    11
    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.
     
    tony_maker likes this.
  3. CaptainOtter

    CaptainOtter

    Joined:
    Aug 27, 2016
    Posts:
    11
    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!
     
    tony_maker and DenisasK like this.
  4. aniketandy141

    aniketandy141

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

    private void HandleAdResult(ShowResult result)
    {
    switch (result)
    {
    case ShowResult.Finished:
    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    DestroyImmediate(this.gameObject);
    break;
    case ShowResult.Skipped:
    Debug.Log("player didnt watch the ad");
    break;
    case ShowResult.Failed:
    Debug.Log("No Internet");
    StartCoroutine(DisplayError());
    break;
    }
    }
    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
  5. tony_maker

    tony_maker

    Joined:
    Apr 17, 2019
    Posts:
    1
    thank you so much guys...it been a great relif for me after the ad is working
    update advertisement form package manger to 3.0.3
     
Thread Status:
Not open for further replies.