Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Bug WaitForCompletion causes the game to hang during scene load

Discussion in 'Addressables' started by RaskinX, Feb 15, 2024.

  1. RaskinX

    RaskinX

    Joined:
    Aug 4, 2021
    Posts:
    8
    Hi, we're using Unity 2022.3.16f1 with Addressables 1.21.19 and have encountered in two separate occasions a game killing bug, where the game hangs indefinitely if any of the game objects in a scene which is being loaded, in their Start() callback call LoadAssetAsync() on an AssetReferenceT<T> and call WaitForCompletion() on their AsyncOperationHandle.

    Unity devs and support -

    1. Is this known?
    2. If yes, is a bugfix coming?
    3. Any workarounds?
     
    yoavhermon and yringel-banditos like this.
  2. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    770
    Hey, so first off I wanted to send you this: https://docs.unity3d.com/Packages/com.unity.addressables@1.21/manual/SynchronousAddressables.html it's our documentation on WaitForCompletion and can show some of the known issues with using that API.

    This exact issue isn't known, but we have seen similar issues when calling WaitForCompletion and some other Addressable APIs as part of a callback. I think your combination of callback + Start() + WaitForCompletion() is probably causing some hang up on either our side, or the engine level load code.

    Something you might try is actually setting some flag as part of the OnComplete of your LoadAssetAsync<T>() call that you're calling in Start(). Once that flag, or whatever, is set, continue your script like normal. It's not going to be 100% synchronous, but it should resolve the deadlock. In order to get a "closer-to-sync" behavior, make sure all your Asset Bundles are local to the device. I assume they probably are since you're testing your game, but I just wanted to call that out. You can use DownloadDependenciesAsync to make sure everything is local/cached beforehand.

    Even if your Bundles are locally built to device, you might still want to call DownloadDependenciesAsync if you're on Android, because Bundle caching can help speed up performance on that platform in particular.
     
  3. RaskinX

    RaskinX

    Joined:
    Aug 4, 2021
    Posts:
    8
    Thanks for the prompt response, in our asset groups config I as per-Unity best practices for Addressables, I set each group to use UnityWebRequest, all groups are local, I indeed observed a smoother experience.

    Would you recommend running DownloadDependenciesAsync() always at startup?