{"record":{"id":"7b82e259c4a62e11","repo":"stride3d/stride","slug":"the-contentscene-has-not-been-initialized-yet","errorCode":null,"errorMessage":"The ContentScene has not been initialized yet.","messagePattern":"The ContentScene has not been initialized yet\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/AssetEditors/EntityHierarchyEditor/Game/EntityHierarchyEditorGame.cs","lineNumber":224,"sourceCode":"            }\n            catch\n            {\n                // TODO: Log or rethrow?\n                renderEffect.State = RenderEffectState.Error;\n                return null;\n            }\n        }\n\n        /// <summary>\n        /// Ensures that the <see cref=\"ContentScene\"/> has been initialized. Otherwise throws an <see cref=\"InvalidOperationException\"/>.\n        /// </summary>\n        /// <seealso cref=\"InitializeContentScene\"/>\n        protected void EnsureContentScene()\n        {\n            if (ContentScene != null)\n                return;\n\n            throw new InvalidOperationException($\"The {nameof(ContentScene)} has not been initialized yet.\");\n        }\n\n        /// <inheritdoc />\n        protected override void Initialize()\n        {\n            base.Initialize();\n\n            // Use a shared database for our shader system\n            // TODO: Shaders compiled on main thread won't actually be visible to MicroThread build engine (contentIndexMap are separate).\n            // It will still work and cache because EffectCompilerCache caches not only at the index map level, but also at the database level.\n            // Later, we probably want to have a GetSharedDatabase() allowing us to mutate it (or merging our results back with IndexFileCommand.AddToSharedGroup()),\n            // so that database created with MountDatabase also have all the newest shaders.\n            ((IReferencable)effectCompiler).AddReference();\n            EffectSystem.Compiler = effectCompiler;\n\n            // Record used effects\n            if (effectLogPath != null)\n            {","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/AssetEditors/EntityHierarchyEditor/Game/EntityHierarchyEditorGame.cs#L206-L242","documentation":"EnsureContentScene is a guard asserting that the editor's ContentScene was already created via InitializeContentScene; if it is still null the editor game is being used before scene initialization and an InvalidOperationException is thrown.","triggerScenarios":"Calling code that depends on ContentScene (entity manipulation, gizmo/selection services) before InitializeContentScene has run, or after scene initialization failed silently.","commonSituations":"Editor plugins accessing the scene during early game lifecycle (before LoadContent completes); failed asset load leaving ContentScene null; calling EnsureContentScene-dependent APIs from async tasks that race initialization.","solutions":["Call/await InitializeContentScene before any code that touches ContentScene","Defer scene-dependent work until the editor game's LoadContent/Initialize completed (await editor game startup)","Check why ContentScene is null: the scene asset may have failed to load","If writing an async task, await a task/event signaling scene readiness instead of assuming it exists"],"exampleFix":"// before\nawait someService.Init(editorGame); // touches ContentScene too early\n// after\nawait editorGame.InitializeContentScene();\nawait someService.Init(editorGame);","handlingStrategy":"validation","validationCode":"if (editorGame.ContentScene == null)\n    throw new InvalidOperationException(\"InitializeContentScene must run before scene access\");","typeGuard":"static bool HasContentScene(EntityHierarchyEditorGame g) => g.ContentScene != null;","tryCatchPattern":"try { EnsureContentScene(); }\ncatch (InvalidOperationException) { await editorGame.InitializeContentScene(); }","preventionTips":["Await InitializeContentScene before scene-dependent editor work","Gate scene access behind editor startup completion events","Treat null ContentScene as 'not ready', not 'empty scene'"],"tags":["csharp","editor","lifecycle","scene"],"backgroundTag":"invalid-state-transition","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}