Configure an instant app for a game using the Google Play Instant Unity plugin

The steps for setting up apps to run on Google Play Instant, as explained in Create your first instant app, also apply to games. This guide emphasizes some setup steps specific to games.

The Google Play Instant Unity plugin configures your project to create an instant app version of your game.

This guide focuses on optimizing your game's download size and ensuring that an install prompt appears when players interact with the instant app version of your game. Before completing the steps on this page, install the Unity Plugin from its Unity Asset Store listing.

Distribute your game's content into asset bundles

If only part of your game is available as an instant app, it's helpful for the user to download your entire game one part at a time. To make this process possible, create an instant app that contains only a simplified loading screen. When the user starts this instant app, your app can then immediately start downloading an asset bundle, or a package of resources, that contains the main game scene from a content delivery network (CDN). Using this strategy, you delay the downloading of most of your game's resources to the time when the player first opens your game.

To implement this distributed downloading solution, complete the following steps:

  1. Use the Asset Bundle Browser plugin to create the asset bundle that represents your game's main scene.
  2. Upload this asset bundle to the location where you serve it to players, ideally using a CDN to reduce download latency. Possible locations could be the following:

  3. Create an instant app that contains the loading screen scene. From this loading screen, your game downloads the asset bundle that contains your game's main scene.

    The following code snippet demonstrates how to download the Asset Bundle and load the scene:

    IEnumerator Start () {
        // Download and load both required scenes.
        yield return StartCoroutine(
            DownloadAsset ("https://ASSETBUNDLE_URL", true));
    }
    
    IEnumerator DownloadAsset(string sceneURL, bool loadScene) {
        // Downloads and loads scenes.
        WWW bundleWWW = WWW.LoadFromCacheOrDownload(sceneURL, 0);
        yield return bundleWWW;
        var assetBundle = bundleWWW.assetBundle;
        if (loadScene) {
            if (assetBundle.isStreamedSceneAssetBundle) {
                string[] scenePaths = assetBundle.GetAllScenePaths();
                string sceneName =
                    System.IO.Path.GetFileNameWithoutExtension(scenePaths[0]);
                SceneManager.LoadScene(sceneName);
            }
        }
    }
    

Optimize your instant app's size

Use Player Settings in the Unity plugin

The Google Play Instant Unity plugin includes the Player Settings dialog, shown in Figure 1, which displays suggestions that help you optimize support for Google Play Instant, develop against more compatible graphics API, and reduce your APK's size.

Specific suggestions include using OpenGLES2 only, disabling
  Multithreaded Rendering, and setting the target SDK version to 26 or
  higher.
Figure 1. The Player Settings dialog

Use Android Player Settings in Unity

If you're using Unity directly, you can reduce the size of your game's instant app by using the Android Player Settings window instead. This window features the following options that you can toggle on and off:

  • Use IL2CPP as scripting backend and enable engine stripping.
  • Use .NET 2.0 Subset as the API compatibility level.
  • Select only ARM under device filtering instead of including both ARM and x86 in the instant app.

Additionally, you can open the Package Manager and disable any packages you won't be using.

Support installation workflows

Because the installation workflow is different for each game, the Google Play Instant Unity plugin doesn't provide one by default. Therefore, you need to add the following logic to enable your game's installation flow:

  • Display the install prompt in your game's instant app.
  • Pass important information about the player's progress—such as their current level, in-game rewards, and customizations—from the instant version of your game to the installed one.

For examples on how to add this logic within your project, see the Unity Engine Features section of the plugin's GitHub project README.