Search Unity

In this post we are going to look at Unity’s new ad service as well as how to integrate it into your current projects. Our goal is to make it easy to make money using your current (or hopefully future) player base with very little overhead and maintenance. We will see exactly what you need to do to integrate advertisements in your project (trust me, it’s not a lot), as well as some of the “gotchas” that might slow you down along the way.

Creating Your Account

Setting up ads in a project is really only a couple of steps. The first thing you will need to do is go to the Unity Ads website and create an account (it’s free and only takes a few minutes). Once you are logged in, you will be presented with the Ads Dashboard. To begin monetizing your project, click “Start Monetizing” (you could also click the “Games” menu item on the left and then “Add New Game”).

Monetize Users

You will then be prompted for some basic information regarding your project. Go ahead and specify your target platform and your project name. If your project is already deployed to market you can look it up. If your project is still in development, don’t worry. There is a link at the bottom you can click to add the development version to your account.

Screen Shot 2015-03-31 at 1.15.46 PM

An interesting takeaway here is that if your game is for both iOS and Android, you will create two different game profiles for the same game in your account. This means that you will have different ad IDs for both versions and thus will be able to track and manage your ads per platform instead of all together.

Now that your game is added to your Unity Ads account, you will be presented with your game dashboard. There are a lot of controls, options, and information panels here, but we are only going to concern ourselves with the “Game ID”. This ID is how we can control the ads shown as well as get the credit for any views or clicks our users provide.

Screen Shot 2015-03-31 at 1.17.29 PM

(This image is from a sample game I have created for this article. I highly recommend you create your own account and game and not use my sample Game ID or else I will get all of the monetization credit for your games. That being said, if you feel like using my Game ID, I won’t stop you. Who doesn’t like free money?)

Integrating Ads into Your Project

Now that you have your Unity Ads account set up, you can begin showing ads in your project. From within Unity, navigate to the Asset Store (Window->Asset Store) and download and import the Unity Ads package. NOTE: currently there will be a warning if you are trying to download the package with Unity 5. This warning is due to the package being uploaded from Unity 4 and is harmless. It just exists currently for backwards compatibility.

Screen Shot 2015-03-31 at 2.32.14 PM

Once the assets are imported into your project, initializing and showing ads is very simple.

NOTE: Since ads are currently only supported for iOS and Android, your editor will have to be targeting one of those platforms in order to see any test ads. Before going further you may want to switch your platform to either iOS or Android in the Unity build settings (File->Build Settings).

In a project, ads are controlled through scripts and there are three lines of code that are absolutely required (and one line of code that should be considered required). The first line is where we give our script access to the Advertisements namespace:

[csharp]using UnityEngine.Advertisements;[/csharp]

Next we must initialize our ads. This can be done anywhere you like, but it must be done before you attempt to show any ads. The first argument of the Initialize() function is the Game ID we got from the Unity Ads website (remember, use your own and not mine). The second argument is whether or not your game is in “test mode”. Generally speaking, while your game is in development you should always leave this as true. We will discuss this more later.

[csharp]Advertisement.Initialize ("29239", true);[/csharp]

Finally we show an advertisement. If we are running our project in the editor we will see a generic billboard ad. If we are running this on device and test mode is set to true (see above) then we will see a placeholder ad. Finally, if we are on device and test mode is false we will see a real live ad.

[csharp]Advertisement.Show ();[/csharp]

Now, initializing the ad system isn’t instantaneous, so you will want to ensure that an ad is ready before attempting to show it. Doing so can prevent errors or bugs that may otherwise plague your experience. You can check that an ad is ready to be shown by using the function isReady()

[csharp]Advertisement.isReady ();[/csharp]

So putting everything together, a simple script to just show an ad when your game starts up could look like this:

[csharp]using UnityEngine;
using UnityEngine.Advertisements;
using System.Collections;

public class SimpleAdScript : MonoBehaviour
void Start ()
Advertisement.Initialize ("29239", true);

StartCoroutine (ShowAdWhenReady ());

IEnumerator ShowAdWhenReady()
while (!Advertisement.isReady ())
yield return null;

Advertisement.Show ();

In the next post we will discuss more advanced ways of using ads as well as how we can build an ad structure using the concepts demonstrated here.

27 replies on “Integrating Unity Ads”

Hi, Am excited about unity ads, simple to integrate,

However, having trouble with wifi ads running time. It takes up to 5 seconds with a black screen no matter what wifi we are on from three different types of phones.

This makes it seem like the game is broken, and people won’t play if on wifi. Works perfect of connected 4g.

Any ideas what this delay is. We are in the States, so shouldn’t be an issue there.



I have Advertisement.Initialize load up during my splash screen, and the ads play later on in the game. I have experienced no lag when starting an ad with wifi.

Hope that helps.

is it still in beta?
what ad does the show() call show? banner interstitial?
and most importantly, are all the necessary listeners in place already?

I will add ads one day I suppose but I haven’t wanted to bother because it’s iOS and Android only and if your build platform isn’t set to one of those then you have to create short-lived bespoke code. I would like to see that I can import and use Unity Ads and for the platforms not yet or ever will be support a nice null stub to keep the excetions from being thrown. :-(

If I only release an app to Amazon’s store, so I never have Google Play store details to enter, am I still paid when ads are viewed?

“Monetize your users with highly relevant content and top rates through incentivized ad views.”

-They live.

perfect for unity 3d learning.

i don’t need any android or ios ADs plugins.

but i have some trouble with unity ads, i do the same code, but i don’t see any ads in my android.

i’m in china.

Thanks for ads features and deloypment tutorial.

I would like to see (from Unity3d team) ads which can be placed as textures on any gameObjects, that could change the ads on much better way :)

It would be nice if you didn’t have to submit invoices to Unity to get paid and you paid on a regular schedule like everyone else.

Thanks for the blog post. Is there any chance that Unity Ads will be avaible for Windows Store soon? I would really appreciate that.

Can I know what will be earning rate, when I compare it with leading ads package Google Admob. Statistics will be much appreciable. Since everyone wants to move on to Unity if they pay better than AdMob.

Never mind, I got it to work by using:

Advertisement.Show(null, new ShowOptions {
resultCallback = result => {
//Ad Callback function here

Did you use the code HTML tag for that? It doesn’t seem to be formatted right.
Advertisement.Show(null, new ShowOptions {
resultCallback = result => {
//Ad Callback function here

Rather than using a lambda expression for delegate assignment, you could use something like this example. Keep an eye on the blog, though. Mike will be going into more detail on method parameters, callbacks, and integration techniques in his next post.

Comments are closed.