Search Unity

(SOLVED) Rewarded Ad not showing (BECAUSE EDITOR MODE)

Discussion in 'Unity Ads & User Acquisition' started by Dudusstar, Apr 21, 2021.

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

    Dudusstar

    Joined:
    Nov 19, 2020
    Posts:
    59
    Hi! I've followed this tutorial to create banner, interstitial and rewarded ads in my android game (when pushing some buttons) but the last one does not work at all. The console debug log tells me that the ad has been loaded but is not showing it.

    Here you have attached the image that proves that the process is working: The ad is loaded and showed.

    I'm working with bolt visual scripting but in this case I'm using some scripts too. I'm using bolt only to trigger the ads, and works perfectly with the banner ad and the interstitial, except for the rewarded ad.

    Here you have the 2 scripts of the tutorial:

    This is the admobAds:

    Code (csharp):
    1. using UnityEngine;
    2. using GoogleMobileAds.Api;
    3. using GoogleMobileAds.Common;
    4. using System;
    5. using Bolt;
    6.  
    7.  
    8. public class AdmobAds : MonoBehaviour
    9. {
    10.     string GameID = "XXXXXXXX";
    11.  
    12.     // Sample ads
    13.     string bannerAdId = "ca-app-pub-3940256099942544/6300978111";
    14.     string InterstitialAdID = "ca-app-pub-3940256099942544/1033173712";
    15.     string rewarded_Ad_ID = "ca-app-pub-3940256099942544/5224354917";
    16.  
    17.  
    18.     public BannerView bannerAd;
    19.     public InterstitialAd interstitial;
    20.     public RewardBasedVideoAd rewardedAd;
    21.  
    22.  
    23.     public static AdmobAds instance;
    24.  
    25.     private void Awake()
    26.     {
    27.         if (instance != null && instance != this)
    28.         {
    29.             Destroy(gameObject);
    30.             return;
    31.         }
    32.         instance = this;
    33.         // DontDestroyOnLoad(this);
    34.  
    35.         rewardedAd = RewardBasedVideoAd.Instance;
    36.     }
    37.  
    38.     // Start is called before the first frame update
    39.     void Start()
    40.     {
    41.         MobileAds.Initialize(GameID);
    42.  
    43.     }
    44.  
    45.     #region rewarded Video Ads
    46.  
    47.     public void loadRewardVideo()
    48.     {
    49.         rewardedAd.LoadAd(new AdRequest.Builder().Build(), rewarded_Ad_ID);
    50.  
    51.  
    52.         rewardedAd.OnAdLoaded += HandleRewardedAdLoaded;
    53.         rewardedAd.OnAdClosed += HandleRewardedAdClosed;
    54.         rewardedAd.OnAdOpening += HandleRewardedAdOpening;
    55.         rewardedAd.OnAdFailedToLoad += HandleRewardedAdFailedToLoad;
    56.         rewardedAd.OnAdRewarded += HandleUserEarnedReward;
    57.         rewardedAd.OnAdLeavingApplication += HandleOnRewardAdleavingApp;
    58.  
    59.     }
    60.  
    61.     /// rewarded video events //////////////////////////////////////////////
    62.  
    63.     public event EventHandler<EventArgs> OnAdLoaded;
    64.  
    65.     public event EventHandler<AdFailedToLoadEventArgs> OnAdFailedToLoad;
    66.  
    67.     public event EventHandler<EventArgs> OnAdOpening;
    68.  
    69.     public event EventHandler<EventArgs> OnAdStarted;
    70.  
    71.     public event EventHandler<EventArgs> OnAdClosed;
    72.  
    73.     public event EventHandler<Reward> OnAdRewarded;
    74.  
    75.     public event EventHandler<EventArgs> OnAdLeavingApplication;
    76.  
    77.     public event EventHandler<EventArgs> OnAdCompleted;
    78.  
    79.     /// Rewared events //////////////////////////
    80.  
    81.  
    82.  
    83.     public void HandleRewardedAdLoaded(object sender, EventArgs args)
    84.     {
    85.         Debug.Log("Video Loaded");
    86.     }
    87.  
    88.     public void HandleRewardedAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
    89.     {
    90.         Debug.Log("Video not loaded");
    91.     }
    92.  
    93.     public void HandleRewardedAdOpening(object sender, EventArgs args)
    94.     {
    95.         Debug.Log("Video Loading");
    96.     }
    97.  
    98.     public void HandleRewardedAdFailedToShow(object sender, AdErrorEventArgs args)
    99.     {
    100.         Debug.Log("Video Loading failed");
    101.     }
    102.  
    103.     public void HandleRewardedAdClosed(object sender, EventArgs args)
    104.     {
    105.         Debug.Log("Video Loading failed");
    106.     }
    107.  
    108.     public void HandleUserEarnedReward(object sender, Reward args)
    109.     {
    110.         /// reward the player here --------------------
    111.         Debug.Log("Player Rewarded");
    112.         GameManager.GMinstance.rewaredPlayer();
    113.  
    114.     }
    115.  
    116.     public void HandleOnRewardAdleavingApp(object sender, EventArgs args)
    117.     {
    118.         Debug.Log("when user clicks the video and open a new window");
    119.     }
    120.  
    121.  
    122.  
    123.     public void showVideoAd()
    124.     {
    125.         if(rewardedAd.IsLoaded())
    126.         {
    127.             rewardedAd.Show();
    128.         }
    129.         else
    130.         {
    131.             Debug.Log("Rewarded Video ad not loaded");
    132.         }
    133.     }


    And this the game manager:


    Code (csharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.SceneManagement;
    6. using Ludiq;
    7. using Bolt;
    8.  
    9. public class GameManager : MonoBehaviour
    10. {
    11.     public static GameManager GMinstance;
    12.  
    13.     private void Awake()
    14.     {
    15.         GMinstance = this;
    16.     }
    17.  
    18.     // Start is called before the first frame update
    19.     void Start()
    20.     {
    21.         AdmobAds.instance.requestInterstital();
    22.         AdmobAds.instance.loadRewardVideo();
    23.     }
    24.     public void rewaredPlayer()
    25.     {
    26.         Debug.Log("rewarding player with ");
    27.         // NEXT LEVEL
    28.     }
    29.  
    30.     public void showBannerAd()
    31.     {
    32.         Debug.Log("Showing banner ad");
    33.         AdmobAds.instance.reqBannerAd();
    34.     }
    35.  
    36.     public void showInterstitialAd()
    37.     {
    38.         Debug.Log("Showing interstitial ad");
    39.         AdmobAds.instance.ShowInterstitialAd();
    40.     }
    41.  
    42.     public void showRewardedAd()
    43.     {
    44.         Debug.Log("Showing rewarded ad");
    45.         AdmobAds.instance.showVideoAd();
    46.     }
    47.  
    48.     public void hideBannerAd()
    49.     {
    50.         Debug.Log("Hiding banner ad");
    51.         AdmobAds.instance.hideBanner();
    52.     }
    53.  
    54.     public void openingMainMenu()
    55.     {
    56.         Debug.Log("Opening Main Menu");
    57.         SceneManager.LoadScene("MainMenu");
    58.     }
    59.  
    60. }
    In visual studio I'm receiving this error but I don't know if it has something to do with it:

    'MobileAds.Initialize(string)' is obsolete: 'Initialize(string appId) is deprecated, use Initialize(Action<InitializationStatus> initCompleteAction) instead.'

    Moreover, I've trying to find a solution in the official admob rewarded ad page but when I look for these instructions I can't find them to check if is the missing part:

    Code (csharp):
    1.  public class GoogleMobileAdsDemoScript : MonoBehaviour
    2. {
    3.     private RewardedAd rewardedAd;
    4.     ...
    5.  
    6.     public void Start()
    7.     {
    8.         ...
    9.  
    10.         this.rewardedAd = new RewardedAd(adUnitId);
    11.  
    12.         // Create an empty ad request.
    13.         AdRequest request = new AdRequest.Builder().Build();
    14.         // Load the rewarded ad with the request.
    15.         this.rewardedAd.LoadAd(request);
    16.     }
    17. }
    18.  
    But I don't know if this is missing inside my script.



    So sorry, I'm a noob game designer with no experience in c# (only visual scripting). I've asked the person who made the tutorial but did not answered.

    Can you please help me? Or tell me where to check?

    Thanks for any kind of help!!!!!!
     

    Attached Files:

    Last edited: Apr 21, 2021
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
  3. Dudusstar

    Dudusstar

    Joined:
    Nov 19, 2020
    Posts:
    59
    Oh crap, ok, I've updated it, sorry! and thanks!
     
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Ok, cool. Now I see there are two scripts and what text isn't part of the code. :D
    Next question is, what is happening? I assume you have a button that the user can click for showVideoAd?

    Are you getting the debug message at that point? If so, then do you get the debug that a video is ready?

    If not, then it would appear your video is ready, but it doesn't play. At that point it's a matter of does admob videos work in editor or what is the behavior in editor. Unless you are testing on mobile also and it's not working.

    Oh, and the message you get does indicate older code. While it should still work, I would suggest considering swapping to help future proof.
     
    Dudusstar likes this.
  5. Dudusstar

    Dudusstar

    Joined:
    Nov 19, 2020
    Posts:
    59
    Yeah! You assume completely right.¡ (thank you again for the mind reading).

    The thing is that I've been checking again the console log and only appears this message before I hit the button:

    Dummy CreateRewardBasedVideoAd

    And once I hit it to show the reward ad, is directly showing me this message:

    Showing rewarded ad

    That means that the rewarded ad is not being loaded. In the admobs script I got these functions:


    Code (csharp):
    1.  
    2.     public void HandleRewardedAdLoaded(object sender, EventArgs args)
    3.     {
    4.         Debug.Log("Video rewarded Loaded");
    5.     }
    6.  
    7.     public void HandleRewardedAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
    8.     {
    9.         Debug.Log("Video rewarded not loaded");
    10.     }
    11.  
    12.     public void HandleRewardedAdOpening(object sender, EventArgs args)
    13.     {
    14.         Debug.Log("Video rewarded Loading");
    15.     }
    16.  
    17.     public void HandleRewardedAdFailedToShow(object sender, AdErrorEventArgs args)
    18.     {
    19.         Debug.Log("Video rewarded Loading failed");
    20.     }
    21.  
    22.     public void HandleRewardedAdClosed(object sender, EventArgs args)
    23.     {
    24.         Debug.Log("Video rewarded Loading failed");
    25.     }
    26.  
    And none of these messages appears in the console log. So I'm guessing that the ad rewarded is not being loaded?
    this next part of the admobs script does that function?

    Code (csharp):
    1.  
    2.  {
    3.         rewardedAd.LoadAd(new AdRequest.Builder().Build(), rewarded_Ad_ID);
    4.  
    5.  
    6.         rewardedAd.OnAdLoaded += HandleRewardedAdLoaded;
    7.         rewardedAd.OnAdClosed += HandleRewardedAdClosed;
    8.         rewardedAd.OnAdOpening += HandleRewardedAdOpening;
    9.         rewardedAd.OnAdFailedToLoad += HandleRewardedAdFailedToLoad;
    10.         rewardedAd.OnAdRewarded += HandleUserEarnedReward;
    11.         rewardedAd.OnAdLeavingApplication += HandleOnRewardAdleavingApp;
    12.  
    13.     }
    14.  
    So sorry, this are hieroglyphic for me.
     
    Niroan likes this.
  6. Dudusstar

    Dudusstar

    Joined:
    Nov 19, 2020
    Posts:
    59
    Maybe this can help: this is the rewardbasedvideoad from the admob, I've not edited it:

    Code (csharp):
    1.  
    2.  
    3. // Copyright (C) 2015 Google, Inc.
    4. //
    5. // Licensed under the Apache License, Version 2.0 (the "License");
    6. // you may not use this file except in compliance with the License.
    7. // You may obtain a copy of the License at
    8. //
    9. //      http://www.apache.org/licenses/LICENSE-2.0
    10. //
    11. // Unless required by applicable law or agreed to in writing, software
    12. // distributed under the License is distributed on an "AS IS" BASIS,
    13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14. // See the License for the specific language governing permissions and
    15. // limitations under the License.
    16.  
    17. using System;
    18.  
    19. using GoogleMobileAds;
    20. using GoogleMobileAds.Common;
    21.  
    22. namespace GoogleMobileAds.Api
    23. {
    24.     public class RewardBasedVideoAd
    25.     {
    26.         private IRewardBasedVideoAdClient client;
    27.         private static readonly RewardBasedVideoAd instance = new RewardBasedVideoAd();
    28.  
    29.         public static RewardBasedVideoAd Instance
    30.         {
    31.             get
    32.             {
    33.                 return instance;
    34.             }
    35.         }
    36.  
    37.         // Creates a Singleton RewardBasedVideoAd.
    38.         private RewardBasedVideoAd()
    39.         {
    40.             this.client = MobileAds.GetClientFactory().BuildRewardBasedVideoAdClient();
    41.             client.CreateRewardBasedVideoAd();
    42.  
    43.             this.client.OnAdLoaded += (sender, args) =>
    44.             {
    45.                 if (this.OnAdLoaded != null)
    46.                 {
    47.                     this.OnAdLoaded(this, args);
    48.                 }
    49.             };
    50.  
    51.             this.client.OnAdFailedToLoad += (sender, args) =>
    52.             {
    53.                 if (this.OnAdFailedToLoad != null)
    54.                 {
    55.                     this.OnAdFailedToLoad(this, args);
    56.                 }
    57.             };
    58.  
    59.             this.client.OnAdOpening += (sender, args) =>
    60.             {
    61.                 if (this.OnAdOpening != null)
    62.                 {
    63.                     this.OnAdOpening(this, args);
    64.                 }
    65.             };
    66.  
    67.             this.client.OnAdStarted += (sender, args) =>
    68.             {
    69.                 if (this.OnAdStarted != null)
    70.                 {
    71.                     this.OnAdStarted(this, args);
    72.                 }
    73.             };
    74.  
    75.             this.client.OnAdClosed += (sender, args) =>
    76.             {
    77.                 if (this.OnAdClosed != null)
    78.                 {
    79.                     this.OnAdClosed(this, args);
    80.                 }
    81.             };
    82.  
    83.             this.client.OnAdLeavingApplication += (sender, args) =>
    84.             {
    85.                 if (this.OnAdLeavingApplication != null)
    86.                 {
    87.                     this.OnAdLeavingApplication(this, args);
    88.                 }
    89.             };
    90.  
    91.             this.client.OnAdRewarded += (sender, args) =>
    92.             {
    93.                 if (this.OnAdRewarded != null)
    94.                 {
    95.                     this.OnAdRewarded(this, args);
    96.                 }
    97.             };
    98.  
    99.             this.client.OnAdCompleted += (sender, args) =>
    100.             {
    101.                 if (this.OnAdCompleted != null)
    102.                 {
    103.                     this.OnAdCompleted(this, args);
    104.                 }
    105.             };
    106.         }
    107.  
    108.         // These are the ad callback events that can be hooked into.
    109.         public event EventHandler<EventArgs> OnAdLoaded;
    110.  
    111.         public event EventHandler<AdFailedToLoadEventArgs> OnAdFailedToLoad;
    112.  
    113.         public event EventHandler<EventArgs> OnAdOpening;
    114.  
    115.         public event EventHandler<EventArgs> OnAdStarted;
    116.  
    117.         public event EventHandler<EventArgs> OnAdClosed;
    118.  
    119.         public event EventHandler<Reward> OnAdRewarded;
    120.  
    121.         public event EventHandler<EventArgs> OnAdLeavingApplication;
    122.  
    123.         public event EventHandler<EventArgs> OnAdCompleted;
    124.  
    125.         // Loads a new reward based video ad request
    126.         public void LoadAd(AdRequest request, string adUnitId)
    127.         {
    128.             client.LoadAd(request, adUnitId);
    129.         }
    130.  
    131.         // Determines whether the reward based video has loaded.
    132.         public bool IsLoaded()
    133.         {
    134.             return client.IsLoaded();
    135.         }
    136.  
    137.         // Shows the reward based video.
    138.         public void Show()
    139.         {
    140.             client.ShowRewardBasedVideoAd();
    141.         }
    142.  
    143.         // Sets the user id of current user.
    144.         public void SetUserId(string userId)
    145.         {
    146.             client.SetUserId(userId);
    147.         }
    148.  
    149.         // Returns the mediation adapter class name.
    150.         public string MediationAdapterClassName()
    151.         {
    152.             return this.client.MediationAdapterClassName();
    153.         }
    154.     }
    155. }
    156.  
     
  7. Dudusstar

    Dudusstar

    Joined:
    Nov 19, 2020
    Posts:
    59
    Ok, so I've just received a call from the world guiness records. And from today I'm the dumest game designer in the world. I've just build the game and the rewarded video worked... It seems that it does not in the editor....

    so sorry x987878979

    I promise I will give you a free code of my game once is published! Thank you for your time, patience and help!
     
    Aligdev likes this.
  8. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Awesome that it works! I haven't used admob, but I'm pretty sure Unity Ads is the same way. I think they just have a message or something to indicate an "ad" has played. I'm glad you got it working! These are things that sometimes have to be worked through.
     
    Dudusstar likes this.
  9. Dudusstar

    Dudusstar

    Joined:
    Nov 19, 2020
    Posts:
    59
    Thank you anyway for your support!! ;)
     
Thread Status:
Not open for further replies.