Rewarded Ads - cleveradssolutions/CAS-Unreal GitHub Wiki
Rewarded ad units enable users to play games, take surveys, or watch videos to earn in-app rewards, such as coins, extra lives, or points.
This guide explains how to integrate rewarded video ads into an Unreal Engine project.
flowchart TD
A[Autoload] -->|auto| L((Load))
L -->|success| R([OnAdLoaded])
L -->|fail| F([OnAdLoadFailed])
F -->|delay| A
R --> RL[IsAdReady]
S((Show)) --> RL
RL -->|success| SR([OnAdDisplayed])
RL -->|fail| SF([OnAdShowFailed])
SR --> I([OnAdsImpression])
SR --> C([OnAdClicked])
I --> UR([OnAdEarnedReward])
UR --> D([OnAdDismissed])
D --> A
SF --> A
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();
[!NOTE]
TheEvent Once
checkbox will fire the Loaded/Failed event only once. ifAutoload Ads
used, events can be triggered many times while the game world exists.
Autoload mode
If enabled, the ad will automatically load new content when the current ad is dismissed or completed. Additionally, it will automatically retry loading the ad if an error occurs during the loading process.
UCASMobileAds::SetAutoloadRewardedAd(true);
You should call LoadRewardedAd()
once to create Ad Instance.
By default, autoloading is defined in the Project Settings -> Plugins -> CAS.AI Config -> Autoload Rewarded Ads
.
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();
Release ad resource
Destroys the ad content and releases any associated resources when the ad is no longer needed to clean up resources and prevent memory leaks.
UCASMobileAds::DestroyRewardedAd();
Call LoadRewardedAd
to load new ad and restore autoload mode if used.
Ad Availability
You can ask for the ad availability directly by calling the following function:
bool AdLoaded = UCASMobileAds::IsRewardedAdReady();
[!IMPORTANT]
We don’t recommend waiting forIsRewardedAdReady
to change each frame. This method call the native SDK and can affect the performance of your game.
Subscribe to theOnRewardedAdLoaded
event instead.
Muted Ads Sounds
Sounds in Rewarded and Rewarded ads mute state. Disabled by default.
UCASMobileAds::SetAdsMuted(Mute);
🔗 Done! What’s Next?
- Try another ad format:
- Read more about Impression level data.