Google is committed to advancing racial equity for Black communities. See how.

Build for Unity

Use this guide to build Play Asset Delivery into your Unity project.

Overview

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. Get the Unity plugin (or package) for Play Asset Delivery.

  2. 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.

  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.

  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 do not 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.

Next step

Integrate Play Asset Delivery into your game or app code using Unity.