Search Unity

Scenes -- Exception: Attempting to use an invalid operation handle

Discussion in 'Addressables' started by senfield, Jul 30, 2019.

  1. senfield

    senfield

    Joined:
    Apr 1, 2019
    Posts:
    31
    I am very puzzled by the purpose of the autoReleaseHandle bool.
    I thought maybe it was a way we could remove the scene from the view and yet keep its SceneInstance around to display again later, but it doesn't seem to be because I get the error:
    "Exception: Attempting to use an invalid operation handle" if I try to reactivate the scene again later.
    What is this boolean parameter for and is there a way to remove and reactivate a scene later?
    Thanks

    Code (CSharp):
    1.         /// <summary>
    2.         /// Release scene
    3.         /// </summary>
    4.         /// <param name="scene">The SceneInstance to release.</param>
    5.         /// <param name="autoReleaseHandle">If true, the handle will be released automatically when complete.</param>
    6.         /// <returns>The operation handle for the request.</returns>
    7.         public static AsyncOperationHandle<SceneInstance> UnloadSceneAsync(SceneInstance scene, bool autoReleaseHandle = true)
    8.         {
    9.             return m_Addressables.UnloadSceneAsync(scene, autoReleaseHandle);
    10.         }
     
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    yeah, we need to clarify our docs and best practices around op handles a little.

    For context, we often talk about pairing a LoadAssetAsync with a Release (for example) as a way to load and release an asset. The reality however is that the Release is actually releasing the AsyncOp. Doing so happens to unload the asset as well, but Release is about the op.

    In the case of UnloadSceneAsync, we return an AsyncOpHandle which points to an AsyncOp. That op will hang around until released. Unless, we auto-release it. So, if you called UnloadSceneAsync with a false, then the AsyncOp would hang around in memory until you released it. Which is admittedly a little non-obvious.

    So we're working on both clarifying the docs, and potentially clarifying the workflow.