Search Issue Tracker

By Design

Votes

0

Found in [Package]

1.23.1

2.3.16

Issue ID

ADDR-3872

Regression

No

Addressable scene Assets lose references in DontDestroyOnLoad when Scenes transition

Package: Addressables

-

How to reproduce:
1. Open the “ADDOL.zip“
2. Open the “Boot Scene“ Scene
3. Open Window > Asset Management > Addressables > Groups
4. Press the Build > New Build > “Default Build Script“
5. Set the Play Mode Script to “Use Existing Build” in the Addressable Groups window
6. Enter Play Mode
7. Wait until the “Main Menu” Scene is loaded
8. Select the “GameObject” GameObject under “DontDestroyOnLoad” in the Hierarchy
9. Observe the Inspector

Expected result: All references remain on the GameObject
Actual result: All references become null

Reproducible in: 1.23.1 (2022.3.58f1), 2.3.16 (6000.0.38f1, 6000.1.0b6, 6000.2.0a3)

Reproduced on: Windows 11 Pro (23H2), macOS 15.3 (M3) (Reporter’s)
Not reproduced on: No other environment tested

Notes:
- The GameObject with the to-be missing references is in the “Splash Scene”
- Any other Play Mode Script yields expected results

  1. Resolution Note:

    According to the Addressables ⁠documentation the reported issue of missing reference seems to be an intended behavior, it is working nature of Addressables to optimize the unused assets in a scene.
    Please see https://docs.unity3d.com/Packages/com.unity.addressables@2.3/manual/UnloadingAddressableAssets.html

    * When we are loading even the addressable scene using Addressables.LoadAsync() with default parameter of LoadSceneMode.Single the Unity runtime unloads the current Scene and calls Resource.UnloadUnusedAssets which unloads assets that are not used.

    * Also, the methods of preserving the assets such as object.DontDestroyOnLoad or HideFlags.DontloadUnusedAsset do not work.

    Unused Assets in Addressables:
    * An asset is deemed to be unused if it isn't reached after walking the whole game object hierarchy, including script components. Static variables are also examined.

    * However, script execution stack is not examined so an asset referenced only from within the script stack will be unloaded. but all the assets other than ScriptableObjects are loaded back in the next time one of its properties or methods is used.

    Workaround as per Addressable Documentation:

    * To prevent the scene and its assets from being unloaded, keep a reference to the scene load operation handle until you want to unload the scene manually.

    * To do this, use ResourceManager.Acquire which Increments reference count of operation handle.

    Example Code:

    private void OnInitCompleted(AsyncOperationHandle<IResourceLocator> obj)
    {
    var handle = Addressables.LoadSceneAsync(m_SceneKey, LoadSceneMode.Single, true);
    resourceManager.Acquire(handle);
    }

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.