Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Second preview build for iOS 9 On Demand Resources and App Slicing support

Discussion in 'iOS and tvOS' started by povilas, Sep 8, 2015.

  1. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    Hello,

    We are releasing a second preview build for iOS 9 On Demand Resources (ODR) and
    App Slicing support. We're planning to release this later in 5.2 cycle. For now
    the build is based on a recent 5.2f2 build with additional fixes from 5.2f3.

    Download link:

    http://beta.unity3d.com/download/747ba33418da/download.html

    For actual ODR and/or App Slicing usage you can check or use either an
    AssetBundle demo located here:

    https://bitbucket.org/Unity-Technologies/assetbundledemo

    or see an example bellow. Note that you need Xcode 7 and iOS 9 for this.

    Changes since last build

    - App Slicing support
    - ODR and sliced resources are stored in asset catalogs. At the moment the only
    API that can retrieve resources in asset catalogs is AssetBundle.CreateFromFile().
    - ODR collection API has been changed to support sliced resources in a
    consistent way

    AssetBundle demo

    Explanation:

    The project contains several demo assets and scenes for ODR and App Slicing demonstration purposes. All assets are put into asset bundles and some of the asset bundles are loaded via ODR on request. Asset bundles are built via separate menu option. When doing an iOS build, the asset bundles are included into Xcode project and configured to be included into Xcode asset catalog. Depending on settings, the asset bundles are configured to be included into the initial app download, or be loaded on demand. In addition, several asset bundles may be assigned to the same path; whichever of them is included into the initial app download, or be loaded on demand depends on device requirements configuration and target device specifics.

    Preparation steps:

    * Extract assetbundle-demo-odr.zip and open demo folder in Unity.
    * Switch platform to iOS
    * Build asset bundles through menu option "AssetBundles->Build
    AssetBundles".
    * Set "Enable on demand resources" iOS player setting.

    Testing ODR:

    * Make the build for AssetLoader or SceneLoader scene. Make sure it's not a development player.
    * Open and run built Xcode project.
    * If everything goes right, in the log you should see messages like:
    [AssetBundleManager] Requesting bundle iOS through ODR
    [AssetBundleManager] Requesting bundle cube.unity3d through ODR
    [AssetBundleManager] Requesting bundle material.unity3d through ODR
    [AssetBundleManager] Requesting bundle texture.unity3d through ODR

    * On a screen you should see a pink texture with Unity logo in the case of AssetLoader scene and a circle in the case of SceneLoader scene.

    Testing App slicing:

    * Make the build for VariantsLoader scene. Make sure it's not a development player.
    * Open and run built Xcode project.
    * If everything goes right, in the log you should see messages like (note that
    ODR is used for some resources)

    [AssetBundleManager] Requesting bundle iOS through ODR
    [AssetBundleManager] Loading variant-scene from variants/variant-scene.unity3d bundle
    [AssetBundleManager] Loading Asset Bundle : variants/variant-scene.unity3d
    [AssetBundleManager] Requesting bundle variants/variant-scene.unity3d through ODR
    [AssetBundleManager] Requesting bundle variants/myassets through asset catalog
    Finished loading scene variant-scene in 0.3671752 seconds
    [AssetBundleManager] variants/variant-scene.unity3d has been unloaded successfully
    [AssetBundleManager] variants/myassets has been unloaded


    * On iPad, "Hi res" text should be visible
    * On iPhone, "Low res" text should be visible

    Troubleshooting:

    * If you get errors like this "This AssetBundle was not created with
    UncompressedAssetBundle flag, expected id 'UnityRaw', got 'UnityWeb'"
    then make sure that platform is set to iOS, delete AssetBundles/iOS folder in
    demo project folder and rebuild the bundles.

    * If you want to run scenes in the editor, then first you need to launch
    asset bundle server through menu option "AssetBundles->Launch
    AssetBundleServer".

    See LoadAssets.cs for an example of how asset bundles are retrieved through
    ODR. If you'd like to use the same infrastructure for your project, then
    just copy demo/Assets/AssetBundleManager folder to your project.


    A quick start guide for ODR

    To Use ODR, first enable ODR feature in iOS player settings: "Enable on
    demand resources", and then add a callback to report a list of ODR
    resources you want to include in the build.

    In the asset bundle demo, the ODR tags attached to reported on demand resources
    must match resource names. There's no such limitation for custom user resources.
    At the moment only asset bundles may be actually read from downloaded asset
    catalogs.

    To set up ODR reporting callback, add a new editor script. Script example:

    Code (csharp):
    1. using UnityEditor.iOS;
    2.  
    3. #if ENABLE_IOS_ON_DEMAND_RESOURCES
    4. public class BuildResources
    5. {
    6.    [InitializeOnLoadMethod]
    7.    static void SetupResourcesBuild()
    8.    {
    9.      UnityEditor.iOS.BuildPipeline.collectResources += CollectResources;
    10.    }
    11.  
    12.    static UnityEditor.iOS.Resource[] CollectResources()
    13.    {
    14.      return new Resource[]
    15.      {
    16.        new Resource("iOS", "AssetBundles/iOS/iOS").AddOnDemandResourceTags("iOS"),
    17.        new Resource("cube.unity3d", "AssetBundles/iOS/cube.unity3d").AddOnDemandResourceTags("cube.unity3d"),
    18.        new Resource("resource", "path/to/resource.file").AddOnDemandResourceTags("resource_tag"),
    19.      };
    20.    }
    21. }
    22. #endif
    An example of actually using those resources:

    Code (csharp):
    1. using UnityEngine.iOS;
    2.  
    3. // Coroutine that can be asynchronously executed with
    4. StartCoroutine(LoadAsset("asset.data"));
    5. public static IEnumerator LoadAsset(string resourceName)
    6. {
    7. // Create the request
    8. var request = OnDemandResources.PreloadAsync(new string[] { "resource_tag"
    9. });
    10.  
    11. // Wait until request is completed
    12. yield return request;
    13.  
    14. // Check for errors
    15. if (request.error != null)
    16.   throw new Exception("ODR request failed: " + request.error);
    17.  
    18. // Get path to the resource and use it. Note that at the moment the only API
    19. // that can load ODR or sliced resources is AssetBundle.CreateFromFile()
    20. var path = "res://" + resourceName;
    21.  
    22. var bundle = AssetBundle.CreateFromFile(path);
    23.  
    24. // Call Dispose() when resource is no longer needed. This will release a
    25. pin on ODR resource.
    26. request.Dispose();
    27. }
    A quick start guide for App Slicing

    To use App Slicing add a callback to report a list of sliced resources you
    want to include in the build. For each resource, several variants may be added
    each of which has corresponding device requirements. For each resource, the
    App Store will select the best variant that matches the device requirements and
    include it into the application bundle.

    Device requirements can be either specified explicitly, or via "variant names"
    which are later configured in the player settings UI. Multiple resource variants
    from different resources may correspond to a single variant name, to which a
    single device requirements definition may be attached.

    At the moment app slicing is implemented only with asset bundle variants in
    mind. App slicing variant names correspond directly to the asset bundle
    variant name. When reporting sliced resources, the variant name must match the
    extension of the asset bundle file (i.e. the asset bundle variant name).

    At the moment, ODR support also needs to be enabled in player settings.

    Sliced resources may also be downloaded on-demand. The process of loading them
    is the same as simple on-demand resources. To set up sliced resource also as
    on-demand resource simply add ODR tags via AddOnDemandResourceTags call.

    To set up app slicing callback, add a new editor script. Script example:

    Code (csharp):
    1.  
    2. using UnityEditor.iOS;
    3.  
    4. #if ENABLE_IOS_APP_SLICING
    5. public class BuildResources
    6. {
    7.    [InitializeOnLoadMethod]
    8.    static void SetupResourcesBuild()
    9.    {
    10.      UnityEditor.iOS.BuildPipeline.collectResources += CollectResources;
    11.    }
    12.  
    13.    static UnityEditor.iOS.Resource[] CollectResources()
    14.    {
    15.      var iPadRequirement = new iOSDeviceRequirement();
    16.      iPadRequirement.values.Add("idiom", "ipad");
    17.  
    18.      return new Resource[]
    19.      {
    20.        // simple sliced resource
    21.        new Resource("variants/myassets").BindVariant("AssetBundles/iOS/variants/myassets.hd", "hd")
    22.                         .BindVariant("AssetBundles/iOS/variants/myassets.sd", "sd"),
    23.  
    24.        // sliced ODR resource
    25.        new Resource("variants/odrassets").BindVariant("AssetBundles/iOS/variants/odrassets.hd", "hd")
    26.                         .BindVariant("AssetBundles/iOS/variants/odrassets.sd", "sd")
    27.                         .AddOnDemandResourceTags("variants/odrassets")
    28.  
    29.        // custom device requirements
    30.        new Resource("variants/odrassets2").BindVariant("AssetBundles/iOS/variants/odrassets2.hd", iPadRequirement)
    31.                         .BindVariant("AssetBundles/iOS/variants/odrassets2.sd", new iOSDeviceRequirement())
    32.                         .AddOnDemandResourceTags("variants/odrassets2")
    33.      };
    34.    }
    35. }
    36. #endif
    37.  
    To use sliced resources, prepend "res://" to the name of the resource and use
    it in Unity APIs that accept filesystem paths. At the moment the only API that
    can load such paths is AssetBundle.CreateFromFile().

    Sliced on demand resources may be downloaded through ODR. The process to load such
    resources is the same as regular ODR resources.

    EDIT: Updated link to a newer demo project, improved explanation.

    EDIT2: Updated link to a open-source demo project repository.
     
    Last edited: Dec 15, 2015
  2. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    ODR and App Slicing support will be officially released in 5.2.0p1.
     
  3. moonjump

    moonjump

    Joined:
    Apr 15, 2010
    Posts:
    2,204
    Does it not remove the 32-bit / 64-bit Unity code so that only the device architecture is supported? If not, is it planned?
     
  4. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    Stripping of unneeded architectures is done on the App Store side.
     
  5. moonjump

    moonjump

    Joined:
    Apr 15, 2010
    Posts:
    2,204
    I thought the app needed to built in a format that allowed the App Store the capability to do that?
     
  6. XCO

    XCO

    Joined:
    Nov 17, 2012
    Posts:
    342
    I got the TV kit :D But this all looks terrifying! lol (Ill figure it out)
     
  7. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    The process is pretty much seamless. One builds the app as usual except that additional flags are passed to xcode.
     
    XCO likes this.
  8. dustinbahr

    dustinbahr

    Joined:
    Sep 10, 2012
    Posts:
    52
    Step one of testing for ODR is confusing: "Make the build for scene."

    Assuming this means build the project with only the SceneLoader scene included in the build?

    Also when building the asset bundles the following error is given: "m_ManagersToReset.empty()" Is this a problem?

    I also don't understand from the instructions where the asset bundles are supposed to go. I see that they are exported to a folder named AssetBundles next to my Unity Assets folder. But how is Xcode supposed to know where these are? Do the AssetBundles need to be hosted somewhere?

    Anyhow, this isn't working for me with either SceneLoader or AssetLoader scene.

    I get the following errors in Xcode when I run the project on my iPhone.

    Also, assuming we get past this issue, what is the process to first test this during development, and then host the bundles on iTunes connect for distribution?
     
  9. dustinbahr

    dustinbahr

    Joined:
    Sep 10, 2012
    Posts:
    52
    Also attempting to view the Resource Tags tab section in Xcode crashes Xcode. (tried both Xcode 7.0 and 7.1 beta)
     
  10. rocket5tim

    rocket5tim

    Joined:
    May 19, 2009
    Posts:
    226
    I'm running into the exact same issues that dustinbahr is reporting. Using build 5.1.4b13.

     
  11. dustinbahr

    dustinbahr

    Joined:
    Sep 10, 2012
    Posts:
    52
    After fooling around with this for far too long I realized the VariantLoader scene DOES work.

    I don't want to use variants OR app slicing so i wasn't trying this before.

    It seems the missing link may be this line of code, and the method that goes with it.
    Code (CSharp):
    1. #ifENABLE_IOS_APP_SLICING
    2. AssetBundleManager.overrideBaseDownloadingURL+=OverrideAppSlicingDownloadingURL;
    3. #endif
    If I add that to the AssetLoader demo script I no longer get those errors.

    I added this to my actual project and things are loading in as expected.

    Can someone from Unity tell us if this is really the fix, and why it is needed?
     
  12. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    It seems that I've accidentally uploaded an older version of the project which had some problems. Please see updated project https://oc.unity3d.com/index.php/s/XOqTDq1PLPjIXwN.
     
  13. dustinbahr

    dustinbahr

    Joined:
    Sep 10, 2012
    Posts:
    52
    Still getting this error when building asset bundles in the updated demo.

    Should I be concerned?
     
  14. dustinbahr

    dustinbahr

    Joined:
    Sep 10, 2012
    Posts:
    52
    Just tested the AssetLoader scene on device. It works great.

    Also to clarify, it seems the overrideBaseDownloadingURL bandaid was not the real issue, and is not used in this updated demo.

    Other than the seemingly harmless error mentioned above when building the asset bundles, this seems to work great!
     
  15. ___Petr___

    ___Petr___

    Joined:
    Jun 4, 2013
    Posts:
    40
    Can you please tell what are these flags?
    Should we set them manually? Or they setted by default?
     
  16. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    This is all handled automatically. You don't need to do anything :)
     
  17. ___Petr___

    ___Petr___

    Joined:
    Jun 4, 2013
    Posts:
    40
    Thank you)
     
  18. oleg-chumakov

    oleg-chumakov

    Joined:
    Oct 30, 2013
    Posts:
    18
  19. oleg-chumakov

    oleg-chumakov

    Joined:
    Oct 30, 2013
    Posts:
    18
    Found the answer. If any build check at iTunes side is failed - ODR resoureces are not proceed. So, e.g. if you are uploading build for tvOS over 200MB, it will be blocked by iTunes Connect before ODR will be checked, so you'll always see:
    On Demand Resources
    Yes 0 Asset Packs
     
  20. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
  21. wgt_jimmy

    wgt_jimmy

    Joined:
    Dec 22, 2014
    Posts:
    39
    Any chance this gets bckported to 4.x?
     
  22. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    Likely no. 4.6 is approaching end of life soon.
     
  23. gregorypierce

    gregorypierce

    Joined:
    Jan 21, 2008
    Posts:
    377
    With On Demand Resources, can I be running the game while some of the data for the next level is loading? I see the information for the Coroutine here, but its not clear if that means I can start streaming in resources while the player is doing other stuff in the game.
     
  24. Mantas-Puida

    Mantas-Puida

    Unity Technologies

    Joined:
    Nov 13, 2008
    Posts:
    1,850
    Yes, this should be possible.
     
  25. Iwanowski

    Iwanowski

    Joined:
    Aug 3, 2015
    Posts:
    3
    Hey,

    when i tried to run demo SceneLoader on device, i'm getting (i have build Asset Bundles):

    [AssetBundleManager] Loading Asset Bundle Manifest: iOS

    <Start>c__Iterator3:MoveNext()


    (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)


    [AssetBundleManager] Requesting bundle iOS through ODR

    <Initialize>c__Iterator4:MoveNext()

    <Start>c__Iterator3:MoveNext()


    (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)


    Failed downloading bundle iOS from odr://iOS: The requested application data doesn’t exist.


    (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)


    [AssetBundleManager] Loading TestScene from scene-bundle bundle


    (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)


    [AssetBundleManager] Loading Asset Bundle : scene-bundle

    <Start>c__Iterator3:MoveNext()


    (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)


    Please initialize AssetBundleManifest by calling AssetBundleManager.Initialize()


    (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

    and when I try view the Resource Tags tab in Xcode, Xcode crashes tried Xcode 7.1 and 7.1.2

    Thanks, for any help :)
     
  26. AndyTehBald

    AndyTehBald

    Joined:
    Oct 27, 2015
    Posts:
    1
    Hi there

    I am trying to move some movies from StreamingAssets into ODR.

    Packing them seems straightforward enough:
    • Move out of /Assets/StreamingAssets
    • new UnityEditor.iOS.Resource(<resourceName>, <path to file>).AddOnDemandResourceTags(<tag>)
    This pops the files into the UnityData.xcassets in Xcode, and all appears good.

    Run-time also almost works, having duplicated most of the classes in AssetBundleLoadOperation.cs, to not auto-create AssetBundles upon completion.

    The question is: "How to I get the on-disk path to the downloaded file"? It seems that your "res://" prefix is not something Mono understands in System.IO.

    I note that OnDemandResourcesRequest.GetResourcePath exists, but I can't get it to return anything other than null. After (request.IsDone && (request.error == null)), I tried passing:
    • <resourceName>
    • "res://" + <resourceName>
    • "UnityData.xcassets/" + <resourceName>
    Is this doable?

    Cheers


    Andy
     
  27. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
  28. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    Unfortunately at the moment On-Demand resources are supported only via asset bundles.
     
  29. Iwanowski

    Iwanowski

    Joined:
    Aug 3, 2015
    Posts:
    3
    Thanks, i got it working :)

    I have one more question, is there any quick and easy way to add progress to LoadLevelAsync? :)
     
  30. paramama

    paramama

    Joined:
    May 10, 2014
    Posts:
    6
    I have a question: test project size about 14 mb, but in TestFlight app size 100 mb (i not added anything). Why size increased
     
  31. d3gator

    d3gator

    Joined:
    May 28, 2009
    Posts:
    20
    Hello,
    I have a few issues with ODR

    First what i have:
    1) I get project as is, nothing changed, from https://bitbucket.org/Unity-Technologies/assetbundledemo
    2) Unity 5.3.2f1
    4) xCode 7.2
    5) I build VariantsLoader scene to test app Slicing - this work's fine when build in debug from xCode directly on device

    What issues i have:
    1) attempting to view the Resource Tags tab section in Xcode crashes Xcode.

    2) Make archive, and try to export it to test slicing shows me error:
    Code (CSharp):
    1. An error occurred during export
    2. Expected asset pack at /OnDemandResources/com.xxxx.yyyy.variants
    So i can't upload it to store and can't export it too.

    3) I need to play video .m4v on ios device from StreamingAssets folder. I have a lot of video files in StreamingAssets folder, so i want to use them with ODR.
    Is there any solution? It seems the problem with getting path to video file from AssetBundle.

    AndyTehBald had the same issue
     

    Attached Files:

  32. hexagonius

    hexagonius

    Joined:
    Mar 26, 2013
    Posts:
    78
    Just found out that the Utility.cs makes use of the UNITY_5_3_1 compiler directive. This needs to be adjusted since we're on UNITY_5_3_2 now. Isn't there a "newer than" or "older than" version directive?
     
  33. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    415
    Hi,

    I have a question regarder ORD - when using a specific tag it's possible to have AssetBundle automatically downloaded according to Apple :

    Initial install tags. The resources are downloaded at the same time as the app. The size of the resources is included in the total size for the app in the App Store. The tags can be purged when they are not being accessed by at least one NSBundleResourceRequest object.

    So if I create AssetBundle - add tag to them - then set those tag as Initial install tag into Xcode - Do I need to use :

    Code (CSharp):
    1. var request = OnDemandResources.PreloadAsync(new string[] { odrTag } );
    What I do not understand - if they are automatically downloaded - how to access to those AssetBundles ?

    If those AssetBundles contain a prefab for instance - but they are not use in the first scene of my game - how to "save" the prefab when the AssetBundles is downloaded at the same time as the application and then be able to access to those prefab later in my game (in other scenes) ?

    Sorry if those questions sound stupid - but I never had to work with AssetBundle before and use those for the first time in an AppleTV game seems complicated to me.

    Thanks you
     
  34. d3gator

    d3gator

    Joined:
    May 28, 2009
    Posts:
    20
    Im playing around with ODR, and can't figere out one issue.
    How to check if the ODR Asset already downloaded and it's exist in cache?

    I will explain in example.
    1) I have LEVEL1 as ODR
    2) I'm requesting LEVEL1 and start game after LEVEL1 loaded.
    3) Here is few situations:
    - a) User have internet connection - successful download LEVEL1 and start game.
    - b) User DON'T have internet connection and step (a) was done earlier, so the ODR somewhere in OnDeamandResource folder, in cache - also success.
    - c) User DON'T have internet connection and LEVEL1 wasn't loaded earlier, we don't have it in cache. In this case these code:

    Code (CSharp):
    1. // Coroutine that can be asynchronously executed with
    2. StartCoroutine(LoadAsset("asset.data"));
    3. public static IEnumerator LoadAsset(string resourceName)
    4. {
    5. // Create the request
    6. var request = OnDemandResources.PreloadAsync(new string[] { "resource_tag"
    7. });
    8. // Wait until request is completed
    9. yield return request;
    10. // Check for errors
    11. if (request.error != null)
    12.   throw new Exception("ODR request failed: " + request.error);
    13. // Get path to the resource and use it. Note that at the moment the only API
    14. // that can load ODR or sliced resources is AssetBundle.CreateFromFile()
    15. var path = "res://" + resourceName;
    16. var bundle = AssetBundle.CreateFromFile(path);
    17. // Call Dispose() when resource is no longer needed. This will release a pin on ODR resource.
    18. request.Dispose();
    19. }
    20.  
    doesn't give me any result. Coroutine is just waiting... For how long should it wait i don't know. In best way i should check if there is and internet connection and only than start Coroutine for asset loading.

    As for me the best way for ODR asset loading is:
    1) Check if ODR asset already loaded. It should be in cache and i can use it.
    2) If not, check for internet connection.
    3) If no connection do nothing(Notify user), If user has internet connection ask for ODR Asset Loading

    So my main question is how to check if the ODR Asset already downloaded?
     
  35. d3gator

    d3gator

    Joined:
    May 28, 2009
    Posts:
    20
    Additionally in ios native code there is a function that check resource:

    https://developer.apple.com/library...yBeginAccessingResourcesWithCompletionHandler:

    Code (CSharp):
    1. - (void)conditionallyBeginAccessingResourcesWithCompletionHandler:(void (^)(BOOL resourcesAvailable))completionHandler
    A block called when the availability of the resources has been checked.

    If the resources marked with the tags managed by the request are already on the device, you can start accessing them as soon as the completion handler is called with resourcesAvailable set to YES. If all of the resources are not already available, you need to call beginAccessingResourcesWithCompletionHandler: to download them from the App Store.


    How to implement similar in Unity?
     
  36. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    415
    Hi guys,

    I used the AssetBundleManager and a modified LoadScene script from the bitbucket in order to download AssetBundle using the OnDemandResource feature for iOS.

    The thing is that I needed to load a scene in background and wait before really load it and replace my current scene. So I modified the LoadScenes.cs in order to be able to access the current asyncOperation request and change the allowSceneActivation to false and then set it back to true when needed.

    I did those modifications real quick in order to test - at the beginning everything looked fines but sometimes even if the allowSceneActivation was set to false the scene will automatically load and replace my current scene as soon as it's ready.

    I noticed that if I use multiple instances of the LoadScenes.cs script I will have multiple instances of the AssetBundleManager in my scene because it creates a GO and pass it to DontDestroyOnLoad method.

    I was wondering if someone tried to make an example script like the LoadScenes script but with the option to set the allowSceneActivation property ?

    I'm really close to finish my project - just need that AssetBundles and ODR to work properly - so any help would be great :)
     
  37. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    No, you need to add tags to xcode either via XcodeAPI or via the GUI. At the moment there's no way to do that.

    You need to put that prefab into a separate asset bundle. The AssetBundle demo project handles resource dependencies, so the asset bundle with the prefab will be downloaded when needed.
     
  38. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    Unfortunately there's no way to do this as of now. I've added this and the initial install tags to the TODO list.
     
  39. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    415
    Hi,

    Is it possible to target device resolution when using variant settings ? I see it's possible to add a custom entry but I have no idea what would be the key for that case.

    Thanks
     
  40. szagii

    szagii

    Joined:
    Jul 13, 2014
    Posts:
    7
    Hi,

    I'm nearly completed implementation of ODR but only I need a way to check if asset is downloaded and exist somewhere in cache :( I understand this is unavailable right now, and there is no workaround? Is any planned date when this feature will be live? :)

    Thanks for any help :)
     
  41. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    No, it's not possible. Only the slicing variants available in Xcode UI are supported.

    Supporting this is in the plans.
     
  42. heritagedevelopment

    heritagedevelopment

    Joined:
    Mar 30, 2015
    Posts:
    7
    Hi,

    I am working on a game and we want to use our 100+ asset bundles with ODR but we didn't find anywhere anything about asset bundle dependencies. How are they handeled?

    Thanks.
     
  43. Mantas-Puida

    Mantas-Puida

    Unity Technologies

    Joined:
    Nov 13, 2008
    Posts:
    1,850
    If you are using Unity 5 Asset Bundle system for all of them, then dependencies between bundles should be tracked automatically.
     
  44. wittywings

    wittywings

    Joined:
    May 23, 2015
    Posts:
    7
    Hello,

    I've been trying to figure out App Slicing in vain. To make things simple, here's what I did:
    • I downloaded the example project on Bitbucket
    • I switched to the iOS Platform
    • I selected the Variant scene.
    • I built Asset Bundles (Assets > Asset Bundles > Build Asset Bundles)
    • I then built the project (Assets > Asset Bundles > Build Player)
    • I opened the project in Xcode and saw that the only variant, non-ODR asset was missing (UnityData.xcassets > variants > logo).
    • When building, I get the following errors:
    Once I run the project on a device, here are the logs:

    I have the same behaviour in my project.

    I'm on Unity 5.3.5f1

    Any ideas?
     
    Last edited: May 28, 2016
  45. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    Hi, I could not reproduce this issue with the latest version of the asset bundle demo project. Have you enabled "Use on demand resources" checkbox in the player settings?
     
  46. mettletech

    mettletech

    Joined:
    Aug 24, 2015
    Posts:
    1
    Hi, I have no such issue like build uploaded successfully and notify in test flight app also but still 0 asset packs . can you help me why it is happening ?? Thank you
     
  47. issfire

    issfire

    Joined:
    Jan 27, 2013
    Posts:
    2
    Hi, I've gotten App Slicing working, a bit of a bumpy ride, for example we tried to bind the same resource twice and received some errors when generating the xcode project.

    There are 2 questions we are trying to figure out.

    1) In the demo project, BuildScript.cs:44, it says that #if ENABLE_IOS_APP_SLICING, then useBuildAssetBundleOptions.UncompressedAssetBundle

    We tested both compressed and uncompressed asset bundles and they seem to work fine with App Slicing and TestFlight, with the difference that the install size is significantly smaller with compression turned on. The uncompressed would probably load a little faster than the compressed, but aside from that, are there any technical reasons "UncompressedAssetBundle" was used in the demo?

    2) We wanted to use AppSlicing only and NOT On-demand-resources. Is it still the case that we have to turn on "Use on demand resources" in the project setting for AppSlicing to work? That would be a bumper because it raises required iOS version to 9.1
     
  48. szagii

    szagii

    Joined:
    Jul 13, 2014
    Posts:
    7
    Hi, after updating to newest patch (5.3.5p5) I'm getting following errors, reverting unity version didn't help :(


    Code (CSharp):
    1. [AssetBundleManager] Requesting bundle iOS through ODR
    2.  
    3. AssetBundles.AssetBundleManager:LoadAssetBundleInternal(String, Boolean)
    4.  
    5. AssetBundles.AssetBundleManager:LoadAssetBundle(String, Boolean)
    6.  
    7. AssetBundles.AssetBundleManager:Initialize(String)
    8.  
    9. Tabasco.<ODRInitialize>c__IteratorD:MoveNext()
    10.  
    11. UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
    12.  
    13.  
    14. (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
    15.  
    16. Failed downloading bundle iOS from odr://iOS
    17.  
    18. AssetBundles.AssetBundleLoadAssetOperationFull:IsDone()
    19.  
    20. AssetBundles.AssetBundleLoadOperation:MoveNext()
    21.  
    22. UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
    23.  
    24.  
    25. (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
    26.  
    27.  
    28. Unhandled Exception: System.NullReferenceException: GetRef
    29.  
    30.   at UnityEngine.AsyncOperation.Finalize () [0x00000] in <filename unknown>:0
    31.  
    32.   at UnityEngine.iOS.OnDemandResourcesRequest.Finalize () [0x00000] in <filename unknown>:0
    33.  
    34. UnityEngine.UnhandledExceptionHandler:PrintException(String, Exception)
    35.  
    36. UnityEngine.UnhandledExceptionHandler:HandleUnhandledException(Object, UnhandledExceptionEventArgs)
    37.  
    38.  
    39. (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
    Thanks for help :)
     
  49. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    192
    Do you mean to say that there's no way to externalise streaming assets using ODR? I'm led to believe the only option for playing movies on iOS and Android is to have those in the Streaming Assets folder. Is there some option for being able to externalise videos in an asset bundle to use with ODR, then on load they'll play on mobile devices?
     
  50. Mantas-Puida

    Mantas-Puida

    Unity Technologies

    Joined:
    Nov 13, 2008
    Posts:
    1,850
    I think it won't work out of the box. Putting streaming assets directly into ODR is possible (via ODR callback), but the loading part would need to be done as native plugin, and you would need to modify video player implementation in Xcode project to take video from ODR.