{"record":{"id":"581566877d44fcb8","repo":"EllanJiang/GameFramework","slug":"scene-asset-0-is-being-unloaded","errorCode":null,"errorMessage":"Scene asset '{0}' is being unloaded.","messagePattern":"Scene asset '(.+?)' is being unloaded\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Scene/SceneManager.cs","lineNumber":373,"sourceCode":"        /// </summary>\n        /// <param name=\"sceneAssetName\">场景资源名称。</param>\n        /// <param name=\"priority\">加载场景资源的优先级。</param>\n        /// <param name=\"userData\">用户自定义数据。</param>\n        public void LoadScene(string sceneAssetName, int priority, object userData)\n        {\n            if (string.IsNullOrEmpty(sceneAssetName))\n            {\n                throw new GameFrameworkException(\"Scene asset name is invalid.\");\n            }\n\n            if (m_ResourceManager == null)\n            {\n                throw new GameFrameworkException(\"You must set resource manager first.\");\n            }\n\n            if (SceneIsUnloading(sceneAssetName))\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Scene asset '{0}' is being unloaded.\", sceneAssetName));\n            }\n\n            if (SceneIsLoading(sceneAssetName))\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Scene asset '{0}' is being loaded.\", sceneAssetName));\n            }\n\n            if (SceneIsLoaded(sceneAssetName))\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Scene asset '{0}' is already loaded.\", sceneAssetName));\n            }\n\n            m_LoadingSceneAssetNames.Add(sceneAssetName);\n            m_ResourceManager.LoadScene(sceneAssetName, priority, m_LoadSceneCallbacks, userData);\n        }\n\n        /// <summary>\n        /// 卸载场景。","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Scene/SceneManager.cs#L355-L391","documentation":"LoadScene throws this formatted error when the requested scene is currently being unloaded (SceneIsUnloading returns true). Concurrently loading a scene that is mid-unload is an invalid state for the scene module, which tracks loads and unloads in separate sets.","triggerScenarios":"Calling LoadScene for an asset name that appears in the unloading set — e.g. rapidly switching back to a scene right after UnloadScene, or two systems triggering load/unload of the same scene concurrently.","commonSituations":"Fast scene switching where the player re-enters the previous scene before its unload completes; duplicate LoadScene calls from multiple procedures responding to the same event.","solutions":["Wait for the unload to finish (subscribe to LoadSceneUpdate/UnloadSceneComplete or check SceneIsUnloading in a loop/state) before loading again","Debounce/deduplicate LoadScene requests for the same asset name","Route scene transitions through a single procedure/state that serializes load and unload operations"],"exampleFix":"// before\nm_SceneManager.LoadScene(sceneAssetName);\n// after\nif (m_SceneManager.SceneIsUnloading(sceneAssetName))\n{\n    // defer: retry when UnloadSceneComplete fires\n    return;\n}\nm_SceneManager.LoadScene(sceneAssetName);","handlingStrategy":"try-catch","validationCode":"if (sceneManager.SceneIsUnloading(sceneAssetName)) { deferLoadUntilUnloadComplete(); return; }","typeGuard":"bool IsSceneLoadable(SceneManager sm, string name) => !sm.SceneIsUnloading(name) && !sm.SceneIsLoading(name) && !sm.SceneIsLoaded(name);","tryCatchPattern":"try { sceneManager.LoadScene(name); } catch (GameFrameworkException ex) when (ex.Message.Contains(\"being unloaded\")) { pendingSceneLoad = name; }","preventionTips":["Serialize scene transitions through one procedure/state","Debounce repeated LoadScene requests for the same scene","Listen for UnloadSceneComplete before re-loading a scene"],"tags":["gameframework","scene","state-conflict"],"backgroundTag":"invalid-state-transition","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}