Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

On Demand Resources not working

Discussion in 'Asset Bundles' started by MeGaBigBoy, Oct 10, 2018.

  1. MeGaBigBoy

    MeGaBigBoy

    Joined:
    Feb 9, 2018
    Posts:
    2
    Hello!

    I have problem with the on demand resource option.

    Here are the main parameters:
    Unity version: 2017.3.1f1
    Xcode version: 9.4.1
    Tested on Device: iPad Air 2 (iOS 11.4.1)

    I went through this tutorial:
    https://docs.unity3d.com/Manual/AppThinning.html

    I was trying to make an AssetBundle from 1 Folder which contains 1 Sprite Atlas and 10 Pictures. Sprite Atlas has unchecked the Include in Build check-mark.

    As the tutorial says I made the „assetcollection” Bundle. „Init” tag is not important I was just trying to fix our problem adding another tag with something to Initial Install Tags.


    I archived and uploaded the project. AppStore processed the project and showed that there are 2 Asset Packs and ODR is Enabled.

    I downloaded and installed the app from TestFlight . When I run the App It shows in console that ODR finished download and then I get the Request Exception. It downloads something but not my uploaded xx MB of data.

    Console log after first Start:

    [ODRDownloadRequest]: Download for com.sunwardgames.differencefeverinitialspots with UUID BC0BEE8E-B656-4217-925D-F835B43A28BC did complete

    [ODRDownloadOperation]: [BC0BEE8E] Request completed successfully

    [ODRClient]: Calling the completion handler. Result [{

    "com.sunwardgames.differencefeverinitialspots.asset-pack-04HBKZWYZI0YJ" = {

    "_NSODRURLKey" = "file:///var/mobile/Library/OnDemandResources/AssetPacks/2C808291-0AAE-4919-936F-9567FF4271D5/3215402020829963239/com.sunwardgames.differencefeverinitialspots.asset-pack-04HBKZWYZI0YJ.assetpack/";

    };

    }] Error [(null)]

    [ODRMobileStoreServices]: ODRDownloadRequest did finish with PID: -2864010334370514937, State: DownloadStateFinished


    Exception: ODR request failed:

    at AssetLoader+<LoadAsset>c__Iterator0.MoveNext () [0x00000] in <00000000000000000000000000000000>:0

    at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0


    (Filename: currently not available on il2cpp Line: -1)



    Console log after second Start:

    [ODRMobileStoreServices]: DestinationURL [file:///var/mobile/Library/OnDemandResources/AssetPacks/2C808291-0AAE-4919-936F-9567FF4271D5/3215402020829963239/com.sunwardgames.differencefeverinitialspots.asset-pack-04HBKZWYZI0YJ.assetpack/] is non-empty. Resource appear to already exists.


    Exception: ODR request failed: (Filename: currently not available on il2cpp Line: -1)



    Loading ( not working for now )

    After chechking request.error I wanted to load the sprites to use them in our scene.
    Bundle = AssetBundle.LoadFromFile("res://" + resourceName);

    Can anyone help me what the problem is here? I also created a new project from scratch just to test this feature but the result is the same.
     
  2. madleen_unity

    madleen_unity

    Unity Technologies

    Joined:
    Aug 28, 2018
    Posts:
    17
    Hi!

    Having checked the code around OnDemandResourcesRequest:
    In the implementation of it, the error is either assigned to an error message or an empty string "";

    So the following snipped taken from the documentation will always trigger the exception:
    Code (CSharp):
    1.  
    2. // Check for errors
    3. if (request.error != null)
    4.             throw new Exception("ODR request failed: " + request.error);
    as the error is always assigned.
    I guess the documentation is wrong and should say
    Code (CSharp):
    1.  
    2. // Check for errors
    3. if (request.error != "")
    4.             throw new Exception("ODR request failed: " + request.error);
    instead.
    I am trying to get the documentation around it changed, but in the meantime see if that resolves your issue.
     
  3. MeGaBigBoy

    MeGaBigBoy

    Joined:
    Feb 9, 2018
    Posts:
    2
    Hi, thank you for your reply. Changing the code helped us to avoid throwing the exception however it did not solve the problem. We still can't manage to use the on demand resource option in Unity.

    Here is what we did. I also uploaded the whole project and this detailed description with screenshots. You can download it from here: http://www.sunwardgames.com/odr/odr.zip (20.4 MB)


    ODR (Step-by-Step)

    Step 1:

    I created SpriteAtlas and added Sprites to it. After that I unchecked the Include in Build Checkmark.



    Step 2:

    I have created „assetcollection” Tag



    Step 3:

    I added all the Sprites and SpriteAtlas to „assetcollection” Tag.

    Step 4:

    I built bundles with BuildiOSAssetBundles script. It contains the SpriteAtlas and all the Sprites in it.



    Step 5:

    I built iOS build. (with Use On Demand Resources).


    Step 6:

    I archived the Project in XCODE.


    Step 7:

    What I see in AppStore Connect Dashboard is that I added 2 Assets (that is correct).


    Step 8:

    I deleted previous install of this app in iPad and installed it again from TestFlight. Before first start of the app I checked the app Size in iPad. (35MB + 4KB Data)

    When I start the app it downloads something (In Console it says DownloadStateFinished), but when I click my button to Instantiate my prefab I cannot see my Sprite on it.

    After second app start Console shows this message : „Resource appear to already exists”.

    App Size is still (35MB + 725 KB Data) it downloaded something but not my 33 MB (Sprite atlas and sprites).

    Loading Assets

    I have a Prefab with SpriteRenderer Component including one of the Sprites in the SpriteAtlas.

    I’m loading assets based on the AppThining tutorial in Unity website.

    Questions:

    How to download my Asset Correctly ( to see the uploaded Data Size ) ?

    How to load my Asset Correctly when I need it ?
     
  4. Chomez217

    Chomez217

    Joined:
    Nov 13, 2019
    Posts:
    1
    Hello madleen, this documentation has still not been changed, just wasted a good couple hours trying to figure out why ODR wasn't working. Would be beneficial to the next person to get this changed ASAP.
     
  5. MrGuardianX

    MrGuardianX

    Joined:
    Sep 29, 2014
    Posts:
    58
    We have the same problem.
    Unity 2018.4.22f1, XCode 12.1

    We use On Install tag, so that the bundle should be downloaded alongside the main app. However this is not the case on some phones (disk space is enough, good internet connection). We see that the callback returns as if the resources are downloaded on device, but when we start to investigate their contents we can't find files of interest there. They are just not present.