Skip to content

Rewarded Ads

Str4tos edited this page May 13, 2024 · 10 revisions

⚡ Before you start
Make sure you have correctly Initialize Ads.

Rewarded ads are ads that users have the option of interacting with in exchange for in-app rewards.

Load an Ad

Call manual load ad before each show if Autoload Rewarded Ads not checked.
In Blueprints you can use Load node just for register Loaded/Failed events.

UCASMobileAds::LoadRewardedAd();
image

Note

The Event Once checkbox will fire the Loaded/Failed event only once. if Autoload Ads used, events can be triggered many times while the game world exists.

Ad Availability

You can ask for the ad availability directly by calling the following function:

bool AdLoaded = UCASMobileAds::IsRewardedAdReady();
image

Important

We don’t recommend waiting for IsRewardedAdReady to change each frame. This method call the native SDK and can affect the performance of your game.
Subscribe to the OnRewardedAdLoaded event instead.

Ad events

To further customize the behavior of your ad, you can hook into a number of events in the ad's lifecycle: loading, opening, closing, and so on. Listen for these events by registering a delegate for the appropriate event, as shown below.

// Called when user earned reward.
UCASMobileAds::OnRewardedAdEarnedReward.AddLambda([=](){
    UE_LOG(LogTemp, Log, TEXT("User Earned reward"));
});
// Called when ad ready to shown.
UCASMobileAds::OnRewardedAdLoaded.AddLambda([=](){
    UE_LOG(LogTemp, Log, TEXT("Rewarded loaded"));
});
// Called when ad failed to load with error.
UCASMobileAds::OnRewardedAdLoadFailed.AddLambda([=](ECASError Error){
    UE_LOG(LogTemp, Log, TEXT("Rewarded failed to load: %s"),
        UCASMobileAds::GetAdsErrorMessage(Error));
});
// Called when the ad shown.
UCASMobileAds::OnRewardedAdDisplayed.AddLambda([=](){
    UE_LOG(LogTemp, Log, TEXT("Rewarded displayed"));
});
// Called when the ad is failed to display.
UCASMobileAds::OnRewardedAdShowFailed.AddLambda([=](ECASError Error){
    UE_LOG(LogTemp, Log, TEXT("Rewarded failed to show: %s"),
        UCASMobileAds::GetAdsErrorMessage(Error));
});
// Called when the user clicks on the Ad.
UCASMobileAds::OnRewardedAdClicked.AddLambda([=](){
    UE_LOG(LogTemp, Log, TEXT("Rewarded clicked"));
});
// Called when the ad is closed.
UCASMobileAds::OnRewardedAdDismissed.AddLambda([=](){
    UE_LOG(LogTemp, Log, TEXT("Rewarded dismissed"));
});

Note

Ad events in Blueprints are registered in the Load and Show nodes. Each new Load/Show Ad node cancels previous node events.

Show the Ad

Before displaying a rewarded ad to users, you must present the user with an explicit choice to view rewarded ad content in exchange for a reward. Rewarded ads must always be an opt-in experience.

Subscribe to OnRewardedAdEarnedReward event to reward the user.

UCASMobileAds::ShowRewardedAd();
image

Muted Ads Sounds

Sounds in Rewarded and Rewarded ads mute state. Disabled by default.

UCASMobileAds::SetAdsMuted(Mute);
image

🔗 Done! What’s Next?