Unity Engine Integration

What’s new in 5.0

Publishers upgrading to the 5.0 MoPub SDK are required to take additional steps. Reference our guides for SDK Initialization and GDPR for more details on how to stay up-to-date and compliant.

Introduction

Unity developers can easily integrate the MoPub SDK along with our mediation adapters via Unity packages. We support Unity 5.5 and above. Follow these steps:

Integrate the Plugin and Adapters

  1. Download the latest MoPub Unity plugin here.

  2. If you would like to use mediation, download the mediation adapters here.

  3. To import the MoPub Unity plugin, double-click on the MoPubUnityPlugin.unitypackage, or go to Assets > Import Package > Custom Package.

  4. Upon importing MoPubUnity.unitypackage, keep all files selected in the Importing Package window and click Import.

    Import Plugin

  5. To import the mediation adapters, double-click on the corresponding network .unitypackage or go to Assets > Import Package > Custom Package. Take AdMob for example:

    Import Adapters

  6. To mediate third-party ad networks, download the certified network SDKs from the link in the MoPub Mediation Integration Tool > Your Network Name > Learn More. Please make sure you are using the cerified version.

    Note: Some networks might also provide a Unity version of their SDK. For AdColony, you need to use its Unity SDK specifically. For other networks, make sure to always download their native Android and iOS SDKs instead in this integration.

  7. Place the network SDKs in your Unity project according to the file extensions, like so:

    SDK File Type Path to place the network SDKs Note
    Android (.aar) [UNITY PROJECT ROOT]/Assets/Plugins/Android If required by networks, add Google Play services aars to this directory.
    Android (.jar) [UNITY PROJECT ROOT]/Assets/Plugins/Android/mopub-support/libs If required by networks, add Google Play services jars to this directory.
    iOS (.framework) [UNITY PROJECT ROOT]/Assets/Plugins/iOS Manually add the frameworks to your project after exporting it to Xcode if need be†

    Place Network SDKs

  8. Before you build your app project, for Android, make sure to add required <Activity> for specific networks if needed (to the AndroidManifest.xml). Please check out the networks’ Android integration guide for details.

  9. Build and run your Unity project. For iOS, after exporting your project into Xcode, ensure MoPubSDKFramework.framework is in the Embedded Binaries list. Otherwise click the + button to add it.

    XCode EB

  10. Ensure the MoPubSDKFramework.framework and other network frameworks are in the Linked Frameworks and Libraries list. Otherwise, click the + button to add them.

    Note: For publishers using MoPub plugin version 5.0+ and Unity version below 2017.1 on iOS, make sure to update to MoPub plugin version 5.0.1 or higher, and review the above steps.

Getting Started with Ads

  1. Follow this instruction to initialize the SDK.

  2. Instantiate the plugin for each ad format. You have to pass in a String array of adunit IDs to the methods as shown in below:

     MoPub.LoadBannerPluginsForAdUnits(_bannerAdUnits);
     MoPub.LoadInterstitialPluginsForAdUnits(_interstitialAdUnits);
     MoPub.LoadRewardedVideoPluginsForAdUnits(_rewardedVideoAdUnits);
     MoPub.LoadRewardedVideoPluginsForAdUnits(_rewardedRichMediaAdUnits);
    
  3. Choose the format you’d like to integrate and follow the instructions for each format:

Additionally, check out this page for other instructions of mediation integration.

Conversion Tracking

Here’s how to report a conversion/app open event:

MoPub.reportApplicationOpen("iTunesAppID");

Here’s how to enable/disable location passing:

MoPub.enableLocationSupport(true);

MoPub.enableLocationSupport(false);

Known Limitations

  • Plugins for the Unity engine do not mediate native ad formats.
  • Developers should test to verify compatibility with other third party plugins.

Last updated September 07, 2018

TWITTER, MOPUB, and the Bird logo are trademarks of Twitter, Inc. or its affiliates. All third party logos and trademarks included are the property of their respective owners.

© 2018 MoPub Inc.