Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Bug (Case 1277297) Calling Resources.Load() while asynchronously loading assetbundle makes app freezed

Discussion in '2020.2 Beta' started by Kichang-Kim, Sep 12, 2020.

  1. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,012
    Hi. I found app freezing issue related to Resources.Load() and AssetBundles.

    If you calling Resources.Load() while asynchronously loading other assets from AssetBundle by using UnityWebRequest, main thread is freezed.

    This only occurred on Android/iOS device, not Editor. And reproduced by both Unity 2020.2.0b2 and 2020.1.5f1.

    Minimal reproducible project was sent as Case 1277297.
     
    Peter77 likes this.
  2. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
    Thanks for the report @Kichang-Kim, we're looking into it.
     
    Kichang-Kim likes this.
  3. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,012
  4. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,012
    I received the response from Unity that "async/await" makes this freezing issue, but I highly doubt it because async/await does not made any special things itself.

    I re-created same reproducible project without async/await and sent modified scripts.

    Also found that calling Resourceds.Load in UnityWebRequestAsyncOperation.completed makes 100% freezing.
     
    LeonhardP likes this.
  5. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,012
    I reported non async/await version of 100% reproducible project as Case 1310359. I hope that this help Unity developers to find and fix freezing issue.
     
  6. ci_playflock

    ci_playflock

    Joined:
    Jul 27, 2020
    Posts:
    4
    Hi!
    We also encountered this problem. Could you please attach a link to Case 1310359 here?
     
  7. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,012
    Unity said 1310359 is merged to 1277297 internally. So you can track ticket status in above link.
     
  8. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
    We have a fix for this issue in review. Backport requests for 20.2 and 21.1 are also going to be evaluated.
     
    Kichang-Kim likes this.
  9. ci_playflock

    ci_playflock

    Joined:
    Jul 27, 2020
    Posts:
    4
    Thank you for your reply
    We use the latest lts Unity for production builds. Is there plans to backport the fix to the 2019.4? We have checked versions 2019.4.9-2019.4.20 and we have the problem there. 2019.4.8 works ok, but we need update for Unity IAP and it needs update of the Unity to the latest version.
     
  10. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
    Hi @ci_playflock,

    The issue reported by @Kichang-Kim was introduced by changes exclusive to version 20.1 and newer. So what you're experiencing must be a similar yet different problem. Could you please submit a bug report for it with a reproducible attached?
     
  11. ci_playflock

    ci_playflock

    Joined:
    Jul 27, 2020
    Posts:
    4
    Hi, LeonhardP,

    Thank you for your response. We will try to reproduce the bug and will send report
     
    LeonhardP likes this.
  12. CodeBombQuinn

    CodeBombQuinn

    Joined:
    Apr 17, 2018
    Posts:
    23
  13. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
    Hi everybody,

    Quick update and correction of my previous statement. We were now able to reproduce the issue reported by @Kichang-Kim in 2019.4 and the fix is being backported. So this might very well be the same problem you're seeing in your projects @ci_playflock @CodeBombQuinn.
     
    CodeBombQuinn and Kichang-Kim like this.
  14. ci_playflock

    ci_playflock

    Joined:
    Jul 27, 2020
    Posts:
    4
    Hi @LeonhardP
    Thank you for your reply! Are there any approximate predictions when the fix will be accepted in 2019.4?
     
    CodeBombQuinn likes this.
  15. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
    It was merged to the 19.4 branch two days ago and should be part of the 2019.4.23f1 release.
     
  16. levelappstudios

    levelappstudios

    Joined:
    Nov 7, 2017
    Posts:
    104
    Hi, we are expecting for the update too. There is an issue with our game (Unity 2019.4.21), it's using AssetBundles with async loading resulting in a very long loading times for some devices (Nexus 5X). Maybe could it be related with this case.

    I tried to do a quick switch to Unity 2021 for checking the fix, but some libraries are not compatible so we will wait for the 2019 release.

    I hope it go out soon.
     
  17. CodeBombQuinn

    CodeBombQuinn

    Joined:
    Apr 17, 2018
    Posts:
    23
    Just confirmed Android working for me now on multiple play throughs with 2019.4.23f1! Thanks for the fix!
     
    LeonhardP likes this.
  18. better_walk_away

    better_walk_away

    Joined:
    Jul 12, 2016
    Posts:
    291
    Is there a download link to the bug-reproducing project? I'm using 2019.4.22f1 and I'm using Resources.Load and Addressables.LoadAssetAsync at the same time somewhere in my project. But I have never encountered this issue up until now. I guess it needs some other preconditions to trigger this bug.
     
  19. better_walk_away

    better_walk_away

    Joined:
    Jul 12, 2016
    Posts:
    291
    I found that if I only allowed one Addressables.LoadAssetAsync command at a time, I could avoid the freeze. So I think if we load multiple AssetBundles asynchronously, we are at risk of app freezing.

    Edit: The freeze still occurred after all, but it was related to using Resources.Load while asynchronously loading an asset bundle.
     
    Last edited: Jul 27, 2022
  20. better_walk_away

    better_walk_away

    Joined:
    Jul 12, 2016
    Posts:
    291
    I encountered this issue sparsely in my project. I am using Unity 2019.4.22f1, which is the version that this fix hasn't been backported. I saw there were indeed "Resources.Load" and "AssetBundleLoadFromAsyncOperation" presented in the same thread. However, I am struggling to reproduce this issue in an empty project. Upgrading Unity engine version is considered a much greater risk in my workplace, workaround is preferred. Can anyone send me a project that can reproduce this issue?
     

    Attached Files:

  21. Wepner-PD

    Wepner-PD

    Joined:
    Jul 13, 2018
    Posts:
    32
    @LeonhardP: we're experiencing a probably similar issue in a project using Unity 2021.3.24. You reported the issue to be (probably) fixed in 2019.4.23. Is this issue fixed in 2021.3.24?
    So far it's rather difficult to tell what the root cause actually is, since we can only observe it rather rarely, and it was so far only observed on some of the target platforms, but (seemingly) not on PC.