Get started
This get started guide will walk you through integrating the Google Mobile Ads into your Unreal project, and then displaying your first ad with it! Here we will focus on an interstitial ad, but detailed guides on implementing different ad formats will be linked at the bottom of the page.
Set up your app in your AdMob account
Register your app as an AdMob app by completing the following steps:
- Sign in to or sign up for an AdMob account.
- Register your app with AdMob. This step creates an AdMob app with a unique AdMob App ID that is needed later in this guide.
Configure your project
Enable the plugin
The plugin is typically enabled by default upon installation. However, if it's not, follow these steps:
- Navigate to Edit > Plugins in Unreal Engine.
- Search for
Google AdMob
in the plugin list. - If the plugin is disabled, enable it by checking the corresponding box.
Disable build-in AdMob support for ads
To avoid any compatibility issues and library conflicts, disable build-in AdMob support. Inside Project Settings, go to Platforms > Android > Google Play Services and set Include AdMob support for ads
to false
.
Enter your App IDs in Project Settings
- Copy your AdMob app ID, as identified in the AdMob web interface. You'll need to separate AdMob apps for Android and iOS, i.e. two different App IDs for these platforms.
- Open Project Settings > Plugins > Google AdMob in Unreal Engine, and paste the copied values into the corresponding AdMob App ID fields.
Enable automatic SDK initialization
Typically, you would want manual control over Privacy & Messaging in your game (it's even required in some cases!), but for this tutorial we are going to ask plugin to attempt initializing Google AdMob SDK automatically at game's start-up. Once again, go to Project Settings > Plugins > Google AdMob, and set the Enable automatic SDK initialization on startup
field to true
(it's disabled be default).
Add dependency to your modules (C++ projects)
To use the plugin in your C++ code, you must include GoogleAdMob
as either a public or private dependency in your module's build configuration, for example:
PrivateDependencyModuleNames.Add("GoogleAdMob");
Implement your first ad
Now you're ready to add your first interstitial ad to your game! Follow the steps below to make it a reality!
-
Create an interstitial ad object and store it in a variable. In Blueprints, add a
Construct Object from Class
node and choose UGoogleAdMobInterstitialAd as a class to create the object from. Think of it as a communication interface between your Unreal project and Google AdMob.// In header file: class UGoogleAdMobInterstitialAd; // ... UPROPERTY() TObjectPtr<UGoogleAdMobInterstitialAd> InterstitialAd; // In source file: #include "GoogleAdMobInterstitialAd.h" // ... InterstitialAd = NewObject<UGoogleAdMobInterstitialAd>(this);
Tip
It's generally recommended to keep your ads in a class/blueprint derived from PlatformGameInstance, as they often need to persist between levels.
-
Check if ads can be requested. Before loading any ads, you should first check if the consent has been gathered from a user using the
UGoogleAdMob::CanRequestAds()
function.// In header file: class UGoogleAdMobInterstitialAd; // ... UPROPERTY() TObjectPtr<UGoogleAdMobInterstitialAd> InterstitialAd; // In source file: #include "GoogleAdMobInterstitialAd.h" #include "GoogleAdMob.h" // ... InterstitialAd = NewObject<UGoogleAdMobInterstitialAd>(this); // ... if (UGoogleAdMob::CanRequestAds()) { // ... }
-
Bind an event to the ad being loaded. Prior to loading the ad, you should also bind some event to the
OnLoaded
multicast delegate, so that you know when your ad is loaded and is ready to be shown.// In header file: class UGoogleAdMobInterstitialAd; // ... UPROPERTY() TObjectPtr<UGoogleAdMobInterstitialAd> InterstitialAd; // In source file: #include "GoogleAdMobInterstitialAd.h" #include "GoogleAdMob.h" #include "GoogleAdMobResponseInfo.h" // ... InterstitialAd = NewObject<UGoogleAdMobInterstitialAd>(this); // ... if (UGoogleAdMob::CanRequestAds()) { InterstitialAd->OnLoaded.AddLambda([](const FGoogleAdMobResponseInfo& ResponseInfo){}); }
-
Load the ad. Now you can finally load your ad by calling
UGoogleAdMobInterstitialAd::Load(const FString& AdUnitID)
function! Just remember that the function must be called on the created ad object (i.e. the function won't appear in Blueprints unless the context menu is shown after dragging the pin from this object), and that there are two different Ad Unit IDs for Android and iOS.// In header file: class UGoogleAdMobInterstitialAd; // ... UPROPERTY() TObjectPtr<UGoogleAdMobInterstitialAd> InterstitialAd; // In source file: #include "GoogleAdMobInterstitialAd.h" #include "GoogleAdMob.h" #include "GoogleAdMobResponseInfo.h" // ... InterstitialAd = NewObject<UGoogleAdMobInterstitialAd>(this); // ... if (UGoogleAdMob::CanRequestAds()) { InterstitialAd->OnLoaded.AddLambda([](const FGoogleAdMobResponseInfo& ResponseInfo){}); #if PLATFORM_ANDROID InterstitialAd->Load(TEXT("ca-app-pub-3940256099942544/1033173712")); #elif PLATFORM_IOS InterstitialAd->Load(TEXT("ca-app-pub-3940256099942544/4411468910")); #endif }
-
Show your interstitial ad. The last step here is obviously showing your ad when it's loaded. Just call
UGoogleAdMobInterstitialAd::Show()
when theOnLoaded
delegate is broadcast, and you're done!// In header file: class UGoogleAdMobInterstitialAd; // ... UPROPERTY() TObjectPtr<UGoogleAdMobInterstitialAd> InterstitialAd; // In source file: #include "GoogleAdMobInterstitialAd.h" #include "GoogleAdMob.h" #include "GoogleAdMobResponseInfo.h" // ... InterstitialAd = NewObject<UGoogleAdMobInterstitialAd>(this); // ... if (UGoogleAdMob::CanRequestAds()) { InterstitialAd->OnLoaded.AddLambda( [InterstitialAd](const FGoogleAdMobResponseInfo& ResponseInfo) { InterstitialAd->Show(); } ); #if PLATFORM_ANDROID InterstitialAd->Load(TEXT("ca-app-pub-3940256099942544/1033173712")); #elif PLATFORM_IOS InterstitialAd->Load(TEXT("ca-app-pub-3940256099942544/4411468910")); #endif }
Congratilations! You've successfully loaded your first interstitial ad! It might seem a bit overwhelming at first, but once you get it, this plugin will become a powerful tool in your developer hands, and will help you implement a robust mobile ad system in your game. Go on and check out what other features it has to offer!