Rewarded Breaks game when I try to load a new scene.

46 views
Skip to first unread message

Papa Bred

unread,
Aug 18, 2024, 9:42:29 PM8/18/24
to Google Mobile Ads SDK Developers
I'm using google AdMob and for some reason when I use a Rewarded Ad and try to load a scene after it doesn't work. I'm trying to make it to where you press a "Start Game" Button and it loads the Ad and when you close the ad it loads the Game Scene. I have it set as when the button and object is deselected it loads the scene. My entire game breaks. Things don't load right and the pause button doesn't work. Is there anyway to fix this?

This is the Rewarded Code.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds;
using GoogleMobileAds.Api;
using System;

public class AdmobRewardedAds : MonoBehaviour
{

    private RewardedAd rewardedAd;

    public string rewardedId = "";

    public static AdmobRewardedAds Instance;

    void Start()

    {

        MobileAds.Initialize((InitializationStatus initStatus) =>
        {
            // This callback is called once the MobileAds SDK is initialized.
            LoadRewardedAd();
        });

    }

    void Awake()
    {
        Instance = this;

    }

    public void LoadRewardedAd()
    {
        // Clean up the old ad before loading a new one.
        if (rewardedAd != null)
        {
            rewardedAd.Destroy();
            rewardedAd = null;
        }

        Debug.Log("Loading the rewarded ad.");

        // create our request used to load the ad.
        var adRequest = new AdRequest();

        // send the request to load the ad.
        RewardedAd.Load(rewardedId, adRequest,
            (RewardedAd ad, LoadAdError error) =>
            {
                // if error is not null, the load request failed.
                if (error != null || ad == null)
                {
                    Debug.LogError("Rewarded ad failed to load an ad " +
                                   "with error : " + error);
                    return;
                }

                Debug.Log("Rewarded ad loaded with response : "
                          + ad.GetResponseInfo());

                rewardedAd = ad;
                RegisterEventHandlers(rewardedAd);
            });
    }

    public void ShowRewardedAd()
    {
        const string rewardMsg =
            "Rewarded ad rewarded the user. Type: {0}, amount: {1}.";

        if (rewardedAd != null && rewardedAd.CanShowAd())
        {
            rewardedAd.Show((Reward reward) =>
            {
                // TODO: Reward the user.
                Debug.Log(String.Format(rewardMsg, reward.Type, reward.Amount));
            });
        }
    }

   
    private void RegisterEventHandlers(RewardedAd ad)
    {
        // Raised when the ad is estimated to have earned money.
        ad.OnAdPaid += (AdValue adValue) =>
        {
            Debug.Log(String.Format("Rewarded ad paid {0} {1}.",
                adValue.Value,
                adValue.CurrencyCode));
        };
        // Raised when an impression is recorded for an ad.
        ad.OnAdImpressionRecorded += () =>
        {
            Debug.Log("Rewarded ad recorded an impression.");
            //HERE WILL GO THE REWARDED VIDEO CALLBACK!!!!
        };
        // Raised when a click is recorded for an ad.
        ad.OnAdClicked += () =>
        {
            Debug.Log("Rewarded ad was clicked.");
        };
        // Raised when an ad opened full screen content.
        ad.OnAdFullScreenContentOpened += () =>
        {
            Debug.Log("Rewarded ad full screen content opened.");
        };
        // Raised when the ad closed full screen content.
        ad.OnAdFullScreenContentClosed += () =>
        {
            Debug.Log("Rewarded ad full screen content closed.");
            LoadRewardedAd();
        };
        // Raised when the ad failed to open full screen content.
        ad.OnAdFullScreenContentFailed += (AdError error) =>
        {
            Debug.LogError("Rewarded ad failed to open full screen content " +
                           "with error : " + error);
            LoadRewardedAd();
        };
    }

}

Mobile Ads SDK Forum Advisor

unread,
Aug 19, 2024, 4:35:21 AM8/19/24
to technical...@gmail.com, google-adm...@googlegroups.com

Hi, 

Thank you for contacting the Mobile Ads SDK support team. 

The code snippet that you have provided is correct and seems like you have followed the rewarded ads for unity guideline. 

Attempting to load a new ad from the ad request completion block when an ad failed to load is strongly discouraged. If you must load an ad from the ad request completion block, limit ad load retries to avoid continuous failed ad requests in situations such as limited network connectivity. Check the Implementation requirements help center article for more information. Can you please confirm whether the mentioned issue is reproducible in our Google sample apps? If yes, Kindly provide the sample project reproducing the issue privately along with the affected app ID and ad unit ID.

You can provide the following details via reply privately to the author option or directly provide it to the link below.

If the file(s) you are looking to share are less than 25mb in total you can attach them to this case on your next reply. If you are having trouble attaching your file to this case or if your file(s) are larger than 25mb, you can share your files with me by performing the following steps:

1. Navigate to

https://docs.google.com/forms/d/e/1FAIpQLSfkAiXMeYP-fw1W3Z-tT9uwmATEKO5X6S-th0gR2ezdKaaqfg/viewform?usp=pp_url&entry.400550049=Mobile+Ads+SDK&entry.460850823=5004Q00002vF6AJQA0&entry.80707362=00263818

2. Fill out all fields, and attach your file(s).

3. Please reply back on this thread when you have uploaded your file(s). Please do not share this link. 

This message is in relation to case "ref:!00D1U01174p.!5004Q02vF6AJ:ref" (ADR-00263818)

Thanks,
 
Google Logo Mobile Ads SDK Team


Reply all
Reply to author
Forward
0 new messages