Search Unity

Fastest load for Asset Bundle

Discussion in 'Scripting' started by Homeak16, Apr 23, 2018.

  1. Homeak16

    Homeak16

    Joined:
    Feb 27, 2017
    Posts:
    19
    Hi,

    i start to use Asset Bundle, and create one what have 82mb whitch contains 1 fbx, 1 prefab, textures, and materials.

    I'm using Unity 2017.4.0f1, free version.

    Problem is, that i tried LoadFromFile, LoadFromFileAsync, LoadFromMemory and LoadFromFileAsync and all these are loading my bundle in 32 seconds!

    So, i wonder, is there another methods what are faster that i already tried.

    Thx!
     
    kwanggary likes this.
  2. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    374
  3. Homeak16

    Homeak16

    Joined:
    Feb 27, 2017
    Posts:
    19
  4. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    Check out the build log for the sizes of your files, maybe you can apply some more compression on the texture for example.

    Did you test on the device or in editor? That will differ greatly too.
     
  5. SlenderBoy302

    SlenderBoy302

    Joined:
    Apr 23, 2017
    Posts:
    7
    Asset Bundle is DEPRECATED now.
     
  6. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    Assetbundles aren't deprecated. What are you referring to?
     
  7. NoDumbQuestion

    NoDumbQuestion

    Joined:
    Nov 10, 2017
    Posts:
    186
    Assetbundle is mostly used for DLC. You download a compressed package then uncompress it. Or use it immediately if asset was packed with LZ4 compression.
    If care about build size and only publish in one-go. Then the best practice for now is using Resources
    The game load all stuff in Resource immediately when "called". The only downsize is you have to manually unload Resource if you dont destroy object that are using file in Resource.

    In my case, I have to load 200 images 1080p in game. Using AssetBundle:
    - No compression: 5-8s open up scene.(99% CPU to uncompress everytime you load from Assetbundle)
    - LZ4 compression: 0.5s to load an image (with high priority). Took me a few minutes to see all Images (the game still run smoothly though).
    - Normal compression: smaller build size. 10-20s to open up scene and load all assetbundle for 1 session.

    When using Resource: file build size = LZ4 assetbundle build.
    - All the images just instantly popup. Open scene only took 2-3s since no images was called.
    - RAM usage will increase to 400Mb if you do no unload Images not used.
     
  8. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
  9. NoDumbQuestion

    NoDumbQuestion

    Joined:
    Nov 10, 2017
    Posts:
    186
    Well I develop game for Android. The only fallback of Assetbundle is that it have to do uncompressing everytime I reopen the app and nothing was cached in disk except ads. Using Resource is much faster for loading on small project since there was not that many stuff to control like in Unity tutorial said.

    And on older mobile device, phone heat up really fast when use assetbundle since it is CPU intensive.
     
  10. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    We use assetbundles in many of the apps on several platforms without issues. We also use resources, though less frequently. Just have to use what is right for the particular feature. There has never been a heat issue with assetbundles either on mobile. They both have their uses.
     
  11. NoDumbQuestion

    NoDumbQuestion

    Joined:
    Nov 10, 2017
    Posts:
    186
    Seem like I have to recheck on Assetbundle later.
     
  12. carlosfarinhas

    carlosfarinhas

    Joined:
    Apr 12, 2016
    Posts:
    10
    Hi Brathnann,
    I use AssetBundles for both iOS and Android.
    But when downloading assetbundles from server on Android, it takes 10 times longer than on iOS!
    Have you ever experience that?
    Best
     
  13. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    I haven't. iOS tends to take longer just due to the assetbundle size and the compression on our images. For our text files that we have bundled, they are similar in size and both download about the same.

    If it's taking longer, compare the size of your bundles and if Android is much larger, you might want to see what is making it larger. If they are similar or Android is smaller, than I'm not sure what is having it take longer for you.
     
  14. carlosfarinhas

    carlosfarinhas

    Joined:
    Apr 12, 2016
    Posts:
    10
    I am using sceneAssetBundles, they are bigger in iOS, but downloading fast. In Android, they are smaller due to compression - normal. For example, I have a scene-bundle that has 5 Mb, if I put it on DropBox server it takes more o less the same time to download (5 seconds) as the ios bundle, and it is fine. But if I use another server (on Android only) it takes like 50 seconds (10 x longer), I am using the same c# scripts just changing servers...
     
  15. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    Well, if one server takes longer than others, I would say it's that server. But honestly, I don't know. I've never had issues with speed on Android.
     
  16. mKhandekar

    mKhandekar

    Joined:
    Sep 20, 2018
    Posts:
    5
    Hey! I'm new to unity and C# scripting. Can you please tell me how did you calculate the download time?
     
  17. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    Careful about using resources. There is a hard limit of 4GB -- go beyond this size and you'll encounter resource data corruption in built players.
     
    ksam2 likes this.
  18. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,080
    I have 300 objects in my asset bundles it takes about 6 seconds to load but I need to make it faster is there any way?
     
  19. NoDumbQuestion

    NoDumbQuestion

    Joined:
    Nov 10, 2017
    Posts:
    186
    You should move on to Addressable System if have time to research.
    And if you think it load slow because of objects numbers.. Most likely you are using loading synchronous (wait for each assets load done before move next) and not asynchronous (load everything in parallel).
    Or the project still load slow due to big files/scenes/textures, it might be bundles included too many asset not need right now in scene. Then chopping down assets into smaller bundles and load it as the game progress.
     
    ksam2 likes this.
  20. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    What Unity version?
    What target platform?
    What type of assets are they?
    What size do these assets have?
    How are you loading them?
    Do you load all 300 assets or just a single asset from the bundle?
     
    ksam2 likes this.
  21. Aleksandr_Novik

    Aleksandr_Novik

    Joined:
    Jul 22, 2018
    Posts:
    2
    Tested: I created a high-poly model and used it as an Asset Bundle. I built it using LZMA compression (which corresponds to BuildAssetBundleOptions.None option) and then loaded and unloaded it 1000 times. I got these results after several iterations:

    LoadFromFile("/directory/") -> 86.9 - 87.0 seconds
    LoadFromMemory(File.ReadAllBytes("/directory/")) -> 88.1 - 88.3 seconds

    So, basically, the difference is not really noticeable and I don't think 1-2 seconds will hugely diminish the loading time. I guess the reason for that is that File.ReadAllBytes() takes those 1-2 seconds in general to convert a file to an array of bytes. If you already have your data encrypted and converted to bytes somewhere, the difference will be even more subtle.