Integrate asset delivery (Unity)

When integrating asset delivery, Unity games can access asset packs using Addressables or AssetBundles. Addressables are the more recent and recommended asset delivery solution for games built with Unity 2019.4 or higher, while AssetBundles provide support of asset packs in Unity 2017.4 and 2018.4.

Unity Addressables

Games built with Unity 2019.4 or higher should use Addressables for asset delivery on Android. Unity provides a Play Asset Delivery (PAD) API for handling Android asset packs using Addressables. For information about using Addressables, see the following:

Use AssetBundle files

Games built with Unity 2017.4 and 2018.4 can use AssetBundle files for asset delivery on Android. Unity AssetBundle files contain serialized assets that can be loaded by the Unity engine while the app is running. These files are platform-specific (for example, built for Android) and can be used in combination with asset packs. Most commonly, one AssetBundle file is packaged into a single asset pack, with the pack using the same name as the AssetBundle. If you want more flexibility in creating an asset pack, configure the asset pack using the API.

At runtime, use the Play Asset Delivery for Unity class to retrieve an AssetBundle packaged in an asset pack.

Prerequisites

  1. Set up your development environment:

OpenUPM-CLI

If you have the OpenUPM CLI installed you can install the OpenUPM registry with the following command:

openupm add com.google.play.assetdelivery

OpenUPM

  1. Open the package manager settings by selecting the Unity menu option Edit > Project Settings > Package Manager.

  2. Add OpenUPM as a scoped registry to the Package Manager window:

    Name: package.openupm.com
    URL: https://package.openupm.com
    Scopes: com.google.external-dependency-manager
      com.google.play.common
      com.google.play.core
      com.google.play.assetdelivery
      com.google.android.appbundle
    
  3. Open the package manager menu by selecting the Unity menu option Window > Package Manager.

  4. Set the manager scope drop-down to select My Registries.

  5. Select the Google Play Integrity plugin for Unity package from the package list and press Install.

Import from GitHub

  1. Download the latest .unitypackage release from GitHub.

  2. Import the .unitypackage file by selecting the Unity menu option Assets > Import package > Custom Package and importing all items.

  1. Create AssetBundles in Unity.

Configure AssetBundles using the UI

  1. Configure each AssetBundle in an asset pack:

    1. Select Google > Android App Bundle > Asset Delivery Settings.
    2. To select folders that directly contain AssetBundle files, click Add Folder.

    Asset Delivery Settings Add Folder button in Unity

  2. For each bundle, change the Delivery Mode to Install Time, Fast Follow, or On Demand. Resolve any errors or dependencies and close the window.

    Asset Delivery delivery mode selector per bundle in Unity

  3. Select Google > Build Android App Bundle to build the app bundle.

  4. (Optional) Configure your app bundle to support different texture compression formats.

Configure asset packs using the API

You can configure asset delivery through editor scripts which can be run as part of an automated build system.

Use the AssetPackConfig class to define which assets to include in an Android App Bundle build, as well as the delivery mode of the assets. These asset packs don't need to contain an AssetBundle.

public void ConfigureAssetPacks {
   // Creates an AssetPackConfig with a single asset pack, named
   // examplePackName, containing all the files in path/to/exampleFolder.
   var assetPackConfig = new AssetPackConfig();
   assetPackConfig.AddAssetsFolder("examplePackName",
                                   "path/to/exampleFolder",
                                   AssetPackDeliveryMode.OnDemand);

   // Configures the build system to use the newly created assetPackConfig when
   // calling Google > Build and Run or Google > Build Android App Bundle.
   AssetPackConfigSerializer.SaveConfig(assetPackConfig);

   // Alternatively, use BundleTool.BuildBundle to build an App Bundle from script.
   BuildBundle(new buildPlayerOptions(), assetPackConfig);
}

You can also use the static BuildBundle method in the Bundletool class to generate an Android App Bundle with asset packs, given BuildPlayerOptions and AssetPackConfig.

For a guided tutorial, see the Using Play Asset Delivery in Unity games Codelab.

Integrate with Play Asset Delivery Unity API

The Play Asset Delivery Unity API provides the functionality for requesting asset packs, managing downloads, and accessing the assets. Make sure to Add the Unity plugin into your project first.

The functions you use in the API depend on how you created the asset packs.

If you created asset packs using the plugin UI, select Plugin-configured asset packs.

If you created asset packs using the API (or plugin UI), select API-configured asset packs.

Next steps

Test asset delivery locally and from Google Play.