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.

8 replies on “Mastering on-demand resources for Apple platforms”

[…] via Mastering on-demand resources for Apple platforms – Unity Blog. […]

[…] developer may also use the counterpart of app slicing, on-demand resources, which we have covered previously. However, in order to use on-demand resources, the app needs to be adapted to download needed […]

[…] Plus, Unity 5.3 also comes with a slew of updates that will allow you to take advantage of new features in iOS 9 and tvOS, including 3D Touch on the iPhone 6S and 6S Plus, support for iPad Pro and Apple Pencil, and Bitcode support. If you want to learn more about using Unity to develop for tvOS and iOS 9 using on-demand resources, head over to our blog post. […]

[…] นอกจากนี้ Unity 5.3 ยังอัพมีการอัพเดทที่จะทำให้เราสามารถใช้ฟีเจอร์ใหม่ ๆ ของ iOS 9 และ tvOS ได้ จนรวมไปถึง 3D Touch บน iPhone 6S และ 6S Plus ที่รองรับ iPad Pro, Apple Pencil, และ Bitcode support (อยากรู้อะไรเพิ่มเติม หรืออยากแสดงความคิดเห็นเพิ่มเติมสามารถเข้าไปได้ที่นี่) […]

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

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?

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.

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!

Comments are closed.