{"record":{"id":"f04d0fac6ae57899","repo":"EllanJiang/GameFramework","slug":"scene-asset-0-is-already-loaded","errorCode":null,"errorMessage":"Scene asset '{0}' is already loaded.","messagePattern":"Scene asset '(.+?)' is already loaded\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Scene/SceneManager.cs","lineNumber":383,"sourceCode":"\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        /// 卸载场景。\n        /// </summary>\n        /// <param name=\"sceneAssetName\">场景资源名称。</param>\n        public void UnloadScene(string sceneAssetName)\n        {\n            UnloadScene(sceneAssetName, null);\n        }\n\n        /// <summary>\n        /// 卸载场景。\n        /// </summary>","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Scene/SceneManager.cs#L365-L401","documentation":"SceneManager.LoadScene throws this when the requested scene asset name is already present in the loaded-scenes set. The framework tracks scene state explicitly and refuses duplicate LoadScene calls instead of reloading or silently ignoring them, because loading an already-loaded scene would corrupt its internal bookkeeping.","triggerScenarios":"Calling SceneManager.LoadScene(sceneAssetName, ...) for a scene asset that was previously loaded successfully and never unloaded, including a second call while an earlier LoadDependencyAsset-style completion is still registered.","commonSituations":"Re-entering a scene without calling UnloadScene first; calling LoadScene from both a menu handler and an initialization routine; duplicating a scene-load call after an async callback fires; scene state desync after an unhandled load failure.","solutions":["Check SceneManager.SceneIsLoaded(sceneAssetName) before calling LoadScene and skip the call if true.","Call UnloadScene(sceneAssetName) first if the scene genuinely needs to be reloaded.","Guard with SceneManager.SceneIsLoading as well to avoid racing an in-flight load.","Wrap LoadScene in try-catch on GameFrameworkException to handle duplicates gracefully."],"exampleFix":"// before\nsceneManager.LoadScene(\"Assets/Scenes/Main.unity\");\n// after\nif (!sceneManager.SceneIsLoaded(\"Assets/Scenes/Main.unity\"))\n{\n    sceneManager.LoadScene(\"Assets/Scenes/Main.unity\");\n}","handlingStrategy":"validation","validationCode":"if (!sceneManager.SceneIsLoaded(sceneAssetName) && !sceneManager.SceneIsLoading(sceneAssetName))\n{\n    sceneManager.LoadScene(sceneAssetName, priority, userData);\n}","typeGuard":null,"tryCatchPattern":"try { sceneManager.LoadScene(sceneAssetName); }\ncatch (GameFrameworkException) { /* scene already loaded; proceed */ }","preventionTips":["Always pair LoadScene with UnloadScene via success/failure events","Centralize scene transitions in one scene-flow manager","Check SceneIsLoaded/SceneIsLoading before any scene call"],"tags":["gameframework","scene-management","duplicate-load","invalid-state-transition"],"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"}