The following code shows you how to bind to delegates and load the first interstitial:
// UMyWidget.cpp (UMyWidget inherits from UObject to access TimerManager) #include "UMyWidget.h"#include "AppLovinMAX.h" // For retry timer logic#include "Async/Async.h"#include "Engine/World.h"#include "TimerManager.h" const FString InterstitialAdUnitId = TEXT("«ad-unit-ID»");int RetryAttempt = 0;FTimerHandle LoadTimerHandle; void UMyWidget::InitializeInterstitialAds(){ // Bind member functions to delegates UAppLovinMAX::OnInterstitialAdLoadedDelegate.AddUObject(this, &UMyWidget::OnInterstitialAdLoaded); UAppLovinMAX::OnInterstitialAdLoadFailedDelegate.AddUObject(this, &UMyWidget::OnInterstitialAdLoadFailed); UAppLovinMAX::OnInterstitialAdDisplayFailedDelegate.AddUObject(this, &UMyWidget::OnInterstitialAdDisplayFailed); UAppLovinMAX::OnInterstitialAdHiddenDelegate.AddUObject(this, &UMyWidget::OnInterstitialAdHidden); // Load first interstitial LoadInterstitial();} void UMyWidget::LoadInterstitial(){ UAppLovinMAX::LoadInterstitial(InterstitialAdUnitId);} void UMyWidget::OnInterstitialAdLoaded(const FAdInfo &AdInfo){ // Interstitial ad is ready to be shown. UAppLovinMAX::IsInterstitialReady(InterstitialAdUnitId) will now return 'true' // Reset retry attempt RetryAttempt = 0;} void UMyWidget::OnInterstitialAdLoadFailed(const FAdInfo &AdInfo, const FAdError &AdError){ // Interstitial ad failed to load // AppLovin recommends that you retry with exponentially higher delays, up to a maximum delay (in this case 64 seconds) RetryAttempt++; AsyncTask(ENamedThreads::GameThread, [this]() { float RetryDelay = FMath::Pow(2.0f, FMath::Min(6, RetryAttempt)); GetWorld()->GetTimerManager().SetTimer(LoadTimerHandle, this, &UMyWidget::LoadInterstitial, RetryDelay, false); });} void UMyWidget::OnInterstitialAdDisplayFailed(const FAdInfo &AdInfo, const FAdError &AdError){ // Interstitial ad failed to display. AppLovin recommends that you load the next ad. LoadInterstitial();} void UMyWidget::OnInterstitialAdHidden(const FAdInfo &AdInfo){ // Interstitial ad is hidden. Pre-load the next ad. LoadInterstitial();}
To show an interstitial ad, call ShowInterstitial():
ShowInterstitial()
if (UAppLovinMAX::IsInterstitialReady(InterstitialAdUnitId)){ UAppLovinMAX::ShowInterstitial(InterstitialAdUnitId);}