Search Issue Tracker
Won't Fix
Won't Fix in 1.21.X, 2.0.X
Votes
2
Found in [Package]
1.21.14
Issue ID
ADDR-3486
Regression
Yes
Freeze when loading the scene asynchronously and using WaitForCompletion()
Reproduction steps:
1. Open the attached project “FreezeRepro“
2. Build and Run (File > Build And Run)
3. Click on the “Goto addressable scene“ button
4. Click on the ”load next addressable scene” button
Expected result: “thirdscene“ scene is loaded
Actual result: Player freezes
Reproducible with: 1.19.18 (2022.1.0a9), 1.19.18, 1.20.5, 1.21.14 (2022.1.0a11, 2022.3.5f1, 2023.1.6f1, 2023.2.0a23)
Not reproducible with: 1.19.17 (2022.1.0a9, 2022.3.5f1, 2023.1.6f1, 2023.2.0a23), 1.19.18, 1.20.5, 1.21.14 (2021.3.28f1)
Couldn’t test with: 1.19.18 (2022.1.0a1-2022.1.0a8), 1.21.14 (2022.1.0a1-2022.1.0a8) - “error CS0246: The type or namespace name 'AssetBundleUnloadOperation' could not be found (are you missing a using directive or an assembly reference?)“, 1.21.14 (2022.1.0a9-2022.1.0a10) - “error CS0103: The name 'enableItemHovering' does not exist in the current context“
Reproducible on: Windows 10
Notes:
The issue can also reproduce in the editor
Not reproducible when starting from the “secondScene“ scene
-
omersimchonimusic
May 19, 2024 08:22
This is extremely ridiculous.
Won't fix?
It's basically freezing the player. So we're forced to stay with 1.19.17 and any version beyond it will completely break the project?
Or try to make some unclean workaround to somehow prevent this from happening?
Makes sense. -
PHNTMBR
Sep 21, 2023 15:09
I can confirm that this issue can be reproduced in 1.21.17 on both Mac and Windows.
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Color mismatch in UI Builders Library panel when the Editors theme is set to Light Mode
- [Android ] "AndroidJNI.ToBooleanArray" returns a random non-zero value instead of "IntPtr.Zero" when the method argument is null
- Non-HDR color picker opens when selecting material color with HDR enabled
- Crash on EditorApplication:Internal_CallUpdateFunctions when pushing property block by index to SpriteShapeRenderer
- Depth Texture Mode "After Opaques" breaks when "Full Screen Pass Renderer Feature" is added
Resolution Note:
There are no fixes planned for this Bug
Resolution Note (2.0.X):
The problem is that the user is calling Addressables.LoadAssetAsync.WaitForCompletion() while the scene is still being loaded. This can block the main thread and prevent other asynchronous operations in progress from completing. In this case UnloadAssetBundle is the operation being blocked.
Addressables has a callback registered to SceneManager.sceneUnloaded += OnSceneUnloaded, which will call Addressables.Release on the currently loaded addressable scene ("second scene"). Since the "second scene" is the only asset currently loaded from its bundle, Release will trigger unloading the bundle. Unloading the bundle used to be a synchronous operation, but in Unity 2022.1 it has become an asynchronous operation to improve performance.
Meanwhile "third scene" is being loaded and the user has a script that calls Addressables.LoadAssetAsync.WaitForCompletion() on Awake. This blocks the main thread and the bundle unload operation can never complete, resulting in an editor freeze.
One workaround is to call Addressables.LoadAssetAsync.WaitForCompletion() in Start() where the scene is finished loading. Currently there is a known bug where calling UnloadAssetBundle while another operation is in progress (i.e. loading the bundle containing the "cube" asset) can cause a deadlock, so we must add a short delay to ensure that UnloadAssetBundle has completed first.
private IEnumerator Start()
{
yield return null;
Addressables.LoadAssetAsync<GameObject>("cube").WaitForCompletion();
}
Another workaround is to prevent the bundle containing "second scene" from being unloaded (when loading "third scene"). This can be done by keeping a reference to "second scene" or assigning the scene to same bundle as other assets (i.e. assign "second scene" to the "Packed Assets" group).
Resolution Note (1.21.X):
The problem is that the user is calling Addressables.LoadAssetAsync.WaitForCompletion() while the scene is still being loaded. This can block the main thread and prevent other asynchronous operations in progress from completing. In this case UnloadAssetBundle is the operation being blocked.
Addressables has a callback registered to SceneManager.sceneUnloaded += OnSceneUnloaded, which will call Addressables.Release on the currently loaded addressable scene ("second scene"). Since the "second scene" is the only asset currently loaded from its bundle, Release will trigger unloading the bundle. Unloading the bundle used to be a synchronous operation, but in Unity 2022.1 it has become an asynchronous operation to improve performance.
Meanwhile "third scene" is being loaded and the user has a script that calls Addressables.LoadAssetAsync.WaitForCompletion() on Awake. This blocks the main thread and the bundle unload operation can never complete, resulting in an editor freeze.
One workaround is to call Addressables.LoadAssetAsync.WaitForCompletion() in Start() where the scene is finished loading. Currently there is a known bug where calling UnloadAssetBundle while another operation is in progress (i.e. loading the bundle containing the "cube" asset) can cause a deadlock, so we must add a short delay to ensure that UnloadAssetBundle has completed first.
private IEnumerator Start()
{
yield return null;
Addressables.LoadAssetAsync<GameObject>("cube").WaitForCompletion();
}
Another workaround is to prevent the bundle containing "second scene" from being unloaded (when loading "third scene"). This can be done by keeping a reference to "second scene" or assigning the scene to same bundle as other assets (i.e. assign "second scene" to the "Packed Assets" group).