Search Unity

On-demand resources is a new iOS feature available since iOS and tvOS version 9.0. Its purpose is to reduce the size of the main application bundle, so that developers can separate certain resources from the main application bundle, host them on App Store infrastructure and download them on-demand.

This is very important on the new AppleTV platform where the main application bundle is limited to 200MB. Therefore, most developers will need to use dynamically loaded resources one way or another. To make developer lives easier, Unity provides an on-demand resources API wrapper which has been shipped in Unity 5.2.0 patch 1.

You can use on-demand resources to both reduce initial application download sizes and reduce the device storage usage by removing no longer needed assets. Generally, any resource that is not strictly needed to launch an app is a candidate for being loaded or unloaded on-demand. For example, consider a level-based game: the application does not need level 10 when the user is still playing level 3. On the other hand, the first levels may be safely unloaded when the user plays level 16.

The most convenient way of taking advantage of on-demand resources is via asset bundles. Asset bundles solve many remaining problems in dynamic asset loading, such as memory and CPU efficiency, dependency tracking and optimization for target platform. Once asset bundles are configured, you need very few additional changes to use on-demand resources, as shown in the code examples below. In this blog post we won’t cover asset bundles. If this is the first time you hear about them, this resource will help you.

In order to use on-demand resources, the developer needs to perform two actions: assign some identifier, called tag, to each resource during build process and request the resources using the assigned tag during app runtime when needed. In vanilla iOS app development, the first step is done by assigning tags to resources in Xcode, whereas resources are requested using NSBundleResourceRequest API. In Unity, both tag assignment and resource retrieval are performed via code: the former via UnityEditor.iOS.BuildPipeline.collectResources event API, and the latter via UnityEngine.iOS.OnDemandResources.PreloadAsync API.

While the current on-demand resources API does not constrain tag names in any way, there are several guidelines that simplify development. It’s best to assign each asset bundle a unique tag which is derived from asset bundle name. This offers most flexibility and it’s also the simplest approach. In this case, the developer will be able to set priority of each individual download and also retrieve progress of each of them. Also, remember that Apple recommends that all the resources which are assigned the same tag have a cumulative size no larger than 64MB for a good balance between download speed and storage space availability.

The following two code examples demonstrate the essence of using on demand resources:

Editor script to assign identifiers to resources:

Resource retrieval during runtime:

 

The easiest way to start exploring asset bundles and on-demand resources is to use our Asset Bundle Manager demo project, which is available on BitBucket. The landing page offers a comprehensible description of how to use and tweak the demo.

Several Unity games utilizing on-demand resources have been already shipped on Apple TV. These include Breakneck and Bruce Lee: Enter the Game – Unchained Edition.

Comments are closed.

  1. any news on when the appltv build target will be available in unity?

  2. i wanna know if support ios8~or ios7…because this is difference from old version assets manager.

    1. No. You can only use it if iOS Deployement Target is set to iOS 9.0.

      Of course in theory you can use OnDemandResources for iOS >= 9.0 and AssetBundles downloaded from www for iOS < 9.0, but you can't publish that app: Apple rejects app if you use OnDemandResources code and iOS Deployement Target is less than 9.0 (tried that).

      1. When you say ‘deployment target’ you mean ‘Target minimum iOS Version’ in Unity player settings?

        1. Yes. Target minimum iOS Version must be set to 9.0.

  3. Sounds cool. The asset bundles seem easy enough to use. But I am put off by the on-demand resource that need us to dip into complicated-looking script in order to use them. Why isn’t there a very simple built-in widget or option in the Unity editor to take all the pain out of this, to just tag resources or whatever and have all of the on-demand management stuff just ‘happen’ automagically?

    1. Scripting based interface gives you best flexibility for integration with your build systems. That’s why we started with it. We are researching how to expose this functionality through GUI in a convenient manner for next updates of this feature.

      1. Yes! Please help us take the pain out of this process with some GUI plug-and-play automagic! Apple TV looks like an exciting platform but all that asset management gives me hives. Help, Unity!