throw exception when unload scene: This exception because not add scene handle to m_resultToHandle at AddressablesImpl.OnSceneHandleCompleted Hope to fix it
I stumbled over the same thing yesterday. The fix was obviously to keep the handle referenced instead of the SceneInstance. I would be curious though for which use case the Addressables.UnloadSceneAsync(SceneInstance instance) API is designed for when it removes the internal dictionary entrance right after loading is completed.
Can you give me some more insights how you solved the problem? Here is a simple example from the Adressables examples. https://github.com/Unity-Technologi...aster/Basic/Scene Loading/Assets/AddScenes.cs who throws same exeption. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement; using UnityEngine.ResourceManagement.AsyncOperations; using UnityEngine.ResourceManagement.ResourceProviders; using UnityEngine.SceneManagement; using UnityEngine.Serialization; using UnityEngine.UI; public class AddScenes : MonoBehaviour { public string addressToAdd; Button m_AddButton; public TMPro.TMP_Text textArea; SceneInstance m_LoadedScene; bool m_ReadyToLoad = true; // Use this for initialization void Start () { m_AddButton = GetComponent<Button>(); m_AddButton.onClick.AddListener(OnButtonClick); textArea.text = "Load " + addressToAdd; } void OnButtonClick() { if(string.IsNullOrEmpty(addressToAdd)) Debug.LogError("Address To Add not set."); else { if (m_ReadyToLoad) Addressables.LoadSceneAsync(addressToAdd, LoadSceneMode.Additive).Completed += OnSceneLoaded; else { Addressables.UnloadSceneAsync(m_LoadedScene).Completed += OnSceneUnloaded; } } } void OnSceneUnloaded(AsyncOperationHandle<SceneInstance> obj) { if (obj.Status == AsyncOperationStatus.Succeeded) { textArea.text = "Reload " + addressToAdd; m_ReadyToLoad = true; m_LoadedScene = new SceneInstance(); } else { Debug.LogError("Failed to unload scene at address: " + addressToAdd); } } void OnSceneLoaded(AsyncOperationHandle<SceneInstance> obj) { if (obj.Status == AsyncOperationStatus.Succeeded) { textArea.text = "Unload " + addressToAdd; m_LoadedScene = obj.Result; m_ReadyToLoad = false; } else { Debug.LogError("Failed to load scene at address: " + addressToAdd); } } } Here is another thread about this problem https://forum.unity.com/threads/0-7-4-unloadscene-problem.666907/
Instead of storing the scene instance, you can keep the whole operation handle and use it to unload: Code (CSharp): using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; using UnityEngine.ResourceManagement.ResourceProviders; using UnityEngine.SceneManagement; using UnityEngine.UI; public class AddScenes : MonoBehaviour { public string addressToAdd; public TMPro.TMP_Text textArea; Button m_AddButton; AsyncOperationHandle<SceneInstance> m_handle; Scene m_scene; bool m_ReadyToLoad = true; void Start() { m_AddButton = GetComponent<Button>(); m_AddButton.onClick.AddListener(OnButtonClick); textArea.text = "Load " + addressToAdd; } void OnButtonClick() { if (string.IsNullOrEmpty(addressToAdd)) Debug.LogError("Address To Add not set."); else { if (m_ReadyToLoad) { m_handle = Addressables.LoadSceneAsync(addressToAdd, LoadSceneMode.Additive); m_handle.Completed += OnSceneLoaded; m_ReadyToLoad = false; } else if (m_handle.IsValid()) { Addressables.UnloadSceneAsync(m_handle).Completed += OnSceneUnloaded; m_handle = default(AsyncOperationHandle<SceneInstance>); } } } void OnSceneUnloaded(AsyncOperationHandle<SceneInstance> obj) { if (obj.Status == AsyncOperationStatus.Succeeded) { textArea.text = "Reload " + addressToAdd; m_ReadyToLoad = true; m_scene = default(Scene); } else { Debug.LogError("Failed to unload scene at address: " + addressToAdd); } } void OnSceneLoaded(AsyncOperationHandle<SceneInstance> obj) { if (obj.Status == AsyncOperationStatus.Succeeded) { textArea.text = "Unload " + addressToAdd; m_scene = obj.Result.Scene; } else { Debug.LogError("Failed to load scene at address: " + addressToAdd); } } }