How do you give different rewards for rewarded ads

Hi all,

Hopefully there’s a straightforward solution to this so I’ll get straight to it.

I’ve set up the Unity Ads script using UnityEngine.Advertisements instead of the old Monetization, but I’ve come across some minor issues with it that I’m struggling to overcome without some workaround.

Using Monetization I could create an ad, have a callback for that ad and set the rewards to give at the end. In the new system you don’t seem to set which callback the ad goes to, so there’s just one for all ads, leaving me wondering how I can give different rewards.

In my AdManager script there are 2 functions (pasted below) that are used, one to play the ad, one for the callback to give rewards. But if I can’t set which callback is used by which ad, then I can only call “ShowRewardedVideo” from any ad button, and then it will always give the same rewards.

Hopefully this make sense, below are the two functions within the AdManager script that I’m using. Any help is appreciated.

public void ShowRewardedVideo()
    {
        if (Advertisement.IsReady(myPlacementId))
        {
            Advertisement.Show(myPlacementId);
        }
        else
        {
            print("Rewarded video not ready");
        }
    }

    public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
    {
        // Define conditional logic for each ad completion status:
        if (showResult == ShowResult.Finished)
        {
            print("Ad completed");
        }
        else if (showResult == ShowResult.Skipped)
        {
            print("Ad skipped");
        }
        else if (showResult == ShowResult.Failed)
        {
            print("Ad failed");
        }
    }

Here is an example of what I’m trying to do from my game:

Rewarded Ad 1
The player presses the button, watches the ad, and is given 100 coins

Reward Ad 2
The player presses the button, watches the ad, and is loaded into a new level

It feels like the only way I can see it’s intended to work is by adding a new placement ID for every rewarded ad you have in your game… which seems crazy as then surely you’re juggling multiple ads to be ready to show, instead of 1/2.

Hi WhiteHotGames,

In this new system the advertisement will call OnUnityAdsDidFinish() when the advertisement ends. When this is called the SDK will provide you with the placementId of the ad and an ad result.

The ad result has 3 main states:

  • Finished - This is means the user watched the ad all the way through
  • Skipped - The user has pressed the skip button if it is available
  • Failed - The ad as failed to show correctly

You should provide the player with a reward if the ad returns ‘finished’ (Line:19). You can use the placementId to determine what reward should be given for each placement. If you want multiple placementIds to have similar behavior you could edit the placementId’s id to contain a key string that you could then look for.

I hope that’s helped

If you don’t want to have multiple placements for different rewards, you could also selectively only add components as listeners when an ad is being shown for that reward. For example, if the 100 coins reward button is pressed, it can add itself as a listener as the ad is being shown, and then remove itself once the ad finishes. That way, you only ever have one listener registered at a time and bypass the issue of multiple callbacks firing.

Thanks for your help guys, I’m going to review the options and see which works best for me.

Out of curiosity, if I did add multiple placementIDs for give different rewards, would it affect the live game?
For example, I currently have “rewardedVideo” as my rewarded ad placementID in my live game. If I were to name the placementIDs more appropriately based on where they’re triggered, and edited this one, would it break in the live version as it’s looking for “rewardedVideo”, which no longer exists?

Too my knowledge changing the placementId in the dashboard without changing the id in the live game will cause ads to stop showing. For now I recommend you setup new placements and hook them up in the next update to your app. This will ensure you don’t break anything for your current users.

1 Like

Hi @WhiteHotGames , did you get to a solution? could you please share with me? I am trying to do this for 2 weeks now.

Hi @Macaquito69

I ended up creating multiple new placement IDs in the Unity dashboard for each ad use in game. This way when I want to trigger an ad I send the string of the ad e.g. “DoubleCoinsResults” to the AdManager, which plays the ad and runs the appropriate callback for the Placement ID, where you can then give the rewards you want by using a switch statement.

It’s a bit lengthier than my old version which would just have the ad code in each script where needed and have it’s own callback, but much more efficient.

Hope that helps!

1 Like

How do you achieve the same with Unity Mediation Reward Ad ?

I wrote below codes for unity 2019.1.9 but when now I transfer to unity 2020.3.45 so I receive Error in scripts RewardedAdsButton.cs Aon below red color codes :

public class RewardedAdsButton : MonoBehaviour, IUnityAdsListener {

and
public void OnUnityAdsDidFinish (string placementId, ShowResult showResult) {

and I receive Errors on script codes: androidplatform.cs on red color :
m_UnityAdsPurchase?.Initialize(this);

so how can I resolve it unity 2020.3.45?
Thanks

IUnityAdsListener and ShowResult have been deprecated in 4.0.0. Please see the deprecated API docs.
https://docs.unity.com/ads/en/manual/DeprecatedAPIClasses

I’m not really sure what the type of this variable, but the error message that showed in your console could be a hint for those errors.

Thanks I used from new codes but I receive Errors again this is link:
https://mega.nz/file/omwjlRoK#sarwGEUoPx25zCjNYDisOFx32vDRMq_UAtQ1l9ZGF_U

Please resolve it

What version of Advertisement package are you using?

I used SDK unity 2.1.0 for unity 2019.1.9 but I Now sdk unity 4.4.1 and unity 2020.3.45 And I receive Error on sdk unity 4.4.1 now

Did you use the asset store version of Unity Ads SDK? In that case you’ll need to remove Unity Ads asset entirely from Assets folder when upgrading to the package manager version. The latest Advertisement package should include those interfaces.

1 Like

Thanks for help
I reinstalled it and It worked but I have problem on new codes
Please see photos

How can I resolve problem
Tganks

8828932--1202116--Screenshot_2023-02-23-13-36-40-883_com.microsoft.rdc.androidx.jpg
8828932--1202119--Screenshot_2023-02-23-13-35-24-418_com.microsoft.rdc.androidx.jpg