{"record":{"id":"51694c672475efd1","repo":"Unity-Technologies/UnityCsReference","slug":"editorapplication-openscene-cannot-be-called-whe","errorCode":null,"errorMessage":"EditorApplication.OpenScene() cannot be called when in the Unity Editor is in play mode.","messagePattern":"EditorApplication\\.OpenScene\\(\\) cannot be called when in the Unity Editor is in play mode\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/EditorApplication.deprecated.cs","lineNumber":39,"sourceCode":"        [Obsolete(\"Use EditorSceneManager.NewScene (NewSceneSetup.EmptyScene)\")]\n        public static void NewEmptyScene()\n        {\n            EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);\n        }\n\n        // Opens the scene at /path/.\n        [Obsolete(\"Use EditorSceneManager.OpenScene\")]\n        public static bool OpenScene(string path)\n        {\n            // Check that we're not in play mode first before opening the scene.\n            if (!isPlaying)\n            {\n                Scene scene = EditorSceneManager.OpenScene(path);\n                return scene.IsValid();\n            }\n            else\n            {\n                throw new InvalidOperationException(\n                    \"EditorApplication.OpenScene() cannot be called when in the Unity Editor is in play mode.\");\n            }\n        }\n\n        [Obsolete(\"Use EditorSceneManager.OpenScene\")]\n        public static void OpenSceneAdditive(string path)\n        {\n            // Case 712517:\n            // Behaviour change introduced in 5.3\n            // Previously we allowed OpenSceneAdditive to be called during playmode.\n            // This is no longer allowed, if it happens we exit playmode which is\n            // consistent with EditorSceneManager.OpenScene(path, OpenSceneMode.Additive)\n\n            if (Application.isPlaying)\n            {\n                Debug.LogWarning(\"Exiting playmode.\\n\" +\n                    \"OpenSceneAdditive was called at a point where there was no active scene.\\n\" +\n                    \"This usually means it was called in a PostprocessScene function during scene loading or it was called during playmode.\\n\" +","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/EditorApplication.deprecated.cs#L21-L57","documentation":"Thrown by the obsolete EditorApplication.OpenScene when EditorApplication.isPlaying is true at call time. The method is marked [Obsolete] (use EditorSceneManager.OpenScene); the play-mode guard is intentional because loading a scene while playing discards runtime state. InvalidOperationException reflects an invalid state for the operation, not a missing resource.","triggerScenarios":"Calling EditorApplication.OpenScene(path) — the deprecated API — from code that runs while the editor is in play mode (an editor script triggered from a play-mode context, a runtime-invoked menu item, etc.).","commonSituations":"Legacy scripts or tutorials still calling EditorApplication.OpenScene; automation that runs without first checking/stopping play mode; ported code from pre-5.3 Unity.","solutions":["Migrate to EditorSceneManager.OpenScene, which exits play mode consistently instead of throwing.","If you must use the deprecated API, stop play mode first: EditorApplication.isPlaying = false; then open.","Guard with: if (EditorApplication.isPlaying) EditorApplication.ExitPlaymode(); before opening."],"exampleFix":"// before\nEditorApplication.OpenScene(scenePath);\n// after\nif (EditorApplication.isPlaying) EditorApplication.ExitPlaymode();\nEditorSceneManager.OpenScene(scenePath);","handlingStrategy":"validation","validationCode":"if (EditorApplication.isPlaying) EditorApplication.ExitPlaymode();\nEditorSceneManager.OpenScene(path);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Stop using the deprecated EditorApplication.OpenScene; migrate to EditorSceneManager.","Stop play mode before any scene-loading automation.","Gate scene-load scripts on !isPlaying when they must run during play."],"tags":["editor","scenemanagement","deprecated","play-mode","obsolete"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}