Problem with Callback OnUnityAdsDidFinish

I have different kind of scripts such as:

Interstacial ads
Rewarded ads

The problem is that whenever e.g. I’m watching an interstacial ad I get the reward from all “active” scripts with OnUnityAdsDidFinish in it. Which runs all my rewards from ALL the scripts with a OnUnityAdsDidFinish in it, even though I have separate placementIds in the different scripts.

public void OnUnityAdsDidFinish(string placementId, ShowResult showResult) {

        if (showResult == ShowResult.Finished)
        {
            MoneyManager.Instance.AddMoney(20);
            Debug.Log("AD ROLL TWO COMPLETE");
        }
        else if (showResult == ShowResult.Skipped)
        {

        }
        else if (showResult == ShowResult.Failed)
        {

        } 
    }

If I have two separate scripts with different placementIDs with addmoney(20) I will get 40 in value instead of 20 as I want.

Am I missing something?

Thanks in advance

I’m running 2019.2.0f1

Hey, did you solve it because I’m having the same issue now.

You need to be checking the placementId in your OnUnityAdsDidFinish callback. Every listener is called when an ad becomes ready, starts, finishes, etc. and the placementId is sent so that you can determine which placement Id the callback is referring to.

Don’t forget to attach the ads listner to your class, where you initialized the ad object.

Something like that:

    private void Start() {
        Advertisement.Initialize(google_id);
        Advertisement.AddListener(this);
    }
7 Likes

For everyone else having the same issue, what I did is to make it so you add Listener when you press the button and remove it when the ad is succesful. This way you avoid having all scripts waiting for an Ad to pop.
Idk if its the best way but it works so :stuck_out_tongue:

2 Likes

I would not recommand adding listeners on the fly, especially on user interaction. If the user spams the button, it may stack your listener several times and this can actually slow your interface because all the listeners copies will be triggered in the same time.
The scripts that dont need the listener will not wait for the ad to pop to do their job, in fact, listeners are kind of asynchronous tasks.

Or you can put a simple check to only add the listener if there’s no listener component attached currently :slight_smile:

It’s more resource consuming this way, your check will be running all the time.

Could Anyone suggest the better way to solve it? I’ve the same issue

Beautt

This worked for me! Thank you!

Thank you for the tip to attach the ads listener, exactly fixed the problem I was having