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

Question Loading simple prefab takes 2-3 seconds on Android

Discussion in 'Addressables' started by Nyankoooo, Sep 12, 2021.

  1. Nyankoooo

    Nyankoooo

    Joined:
    May 21, 2016
    Posts:
    144
    I'm currently testing my app on Android and noticed that some Prefabs (marked as Addressables) have very long loading times of 2-3 seconds per Prefab.

    The Addressable Group the Prefabs are in has CRC disabled, compression set to LZ4 and the Bundle Mode as "Pack Separatly".
    "Contiguous Bundle" is also activated.

    Is there a way to see why an Addressable loaded via LoadAssetAsync (or even InstantiateAsync) takes so long?
    I already checked the Profiler, but can't really see any options to see why loading times are so long.

    Addressable version: 1.18.15
    Unity version: 2020.3.17f1

    Any help, hints and/or tips are greatly appreciated!
     
    Last edited: Sep 12, 2021
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,589
    Have you tried to enable the
    Contiguous Bundles
    setting found in the
    AddressableAssetSettings
    file?

    upload_2021-9-12_7-14-56.png
     
  3. Raghavendra

    Raghavendra

    Joined:
    Mar 14, 2014
    Posts:
    52
    For some reason turning on that option causes this issue in my game, at least in iOS. They load instantly when I turn the setting off.
     
  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,431
    Loading Async will likely not show up in the CPU Profilers Hierarchy view when it's set to main thread, as it's hopping over some threads. You'll probably want to look at this with Timeline view, checking out the loading threads and turning on Flow Event visualization.
     
  5. Nyankoooo

    Nyankoooo

    Joined:
    May 21, 2016
    Posts:
    144
    Ah, I forgot to mention this! Yes, I had this already enabled.
     
  6. Nyankoooo

    Nyankoooo

    Joined:
    May 21, 2016
    Posts:
    144
    @MartinTilo Thank you for the hint.

    It shows that "Application.Preload Assets" and "Loading.Perform [Preloading assets]" are taking 1500-3000ms, which matches the loading times we see in our Android app.
    The issue here is that we don't see why this is happening. Shortly before displaying the loaded asset, even the Profiler freezes until the Prefab is displayed.

    We reduced the Prefab for testing to only a 2D Image with no Sprite set, so there is nothing that should take a long time to load.
     
    Last edited: Sep 15, 2021
  7. Nyankoooo

    Nyankoooo

    Joined:
    May 21, 2016
    Posts:
    144
    @MartinTilo We tested the Prefab with compression set to Uncompressed, and it seems this doesn't make a difference compared to LZ4.
     
  8. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,431
    Does the profiler not show loading samples for individual items?
     
  9. Nyankoooo

    Nyankoooo

    Joined:
    May 21, 2016
    Posts:
    144
    @MartinTilo Do you have a screenshot that shows where to find this?
     
  10. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,431
    It might be that some of the details in these screenshots are only there in +2021.2 versions where the instrumentation of the I/O samples was improved along with the addition of the Asset Loading and the File Access Profiler Modules (and some of their content also got an update with the improvement of timeline tool tip time summaries and the samples selection UX), but iirc some File.Read MetaData (such as the file name) and the flow events for Async loading should be there in 2020.3 already.
     

    Attached Files:

  11. Nyankoooo

    Nyankoooo

    Joined:
    May 21, 2016
    Posts:
    144
    @MartinTilo After looking for these details, I noticed that the huge loading delay was caused by an AudioClip being loaded in the background at the same time. As soon as the AudioClip was loaded, the "troublesome" Prefab loaded without issues.

    Is there a way to load the AudioClip (also an Addressable) at the same time or with lower priority than other Addressables?
     
    Last edited: Sep 17, 2021
  12. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,431
    I'd say if the audio clip isn't referenced from the prefab, it should probably be possible. I just have too little info about how and what you're loading.
     
  13. Nyankoooo

    Nyankoooo

    Joined:
    May 21, 2016
    Posts:
    144
    @MartinTilo When the Scene starts, I load the AudioClip via
    await Addressables.LoadAssetAsync<AudioClip>("Sounds/BGM/bgmName.wav");

    When I then tap on a UI button to open a menu (the Prefab that had issues loading), I'm calling from another script
    var prefab = await Addressables.LoadAssetAsync<GameObject>(menuAssetReference);
    Instantiate(prefab, transform);

    The AudioClip and the Prefab are unrelated from each other. Loading times for the AudioClip are around 2-3 seconds (which is expected for a BGM?).
     
  14. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,431
    Hmm, I'm not too firm on addressables but from a cursory glance at the API docs, I couldn't see a way to prioritize these requests. So it looks like you might have to prioritize them by how you order the LoadAssetAsync requests...
     
  15. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,589
    Can you isolate it in a new project to reproduce the problem? Then you could upload it and people can take a look what the issue might be.
     
  16. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,431
    @Peter77 Tbh it sounds to me like the async loading pipeline ist just a regular FIFO queue without prioritization so if the audio was scheduled for loading first, it'll hold up loading requests that come up after it.
     
    Peter77 likes this.