{"record":{"id":"b02bfe8d3248cb90","repo":"bevyengine/bevy","slug":"attempted-to-include-cached-scene-id-id-path","errorCode":null,"errorMessage":"Attempted to include cached scene (id {id:?}, path: {path:?}), but the resolved scene already has templates. For correctness, the cached scene should always be included first.","messagePattern":"Attempted to include cached scene \\(id (.+?), path: (.+?)\\), but the resolved scene already has templates\\. For correctness, the cached scene should always be included first\\.","errorType":"exception","errorClass":"CachedSceneError","httpStatus":null,"severity":"error","filePath":"crates/bevy_scene/src/resolved_scene.rs","lineNumber":600,"sourceCode":"    /// resolved scene.\n    pub(crate) duplicate_templates: HashSet<TypeId>,\n}\n\n/// The error returned by [`ResolvedScene::include_cached`].\n#[derive(Error, Debug)]\npub enum CachedSceneError {\n    /// Caused when attempting to include a second cached scene.\n    #[error(\n        \"Attempted to include a second cached scene (id {id:?}, path: {path:?}), which is not allowed.\"\n    )]\n    MultipleCached {\n        /// The asset id of the second cached scene.\n        id: UntypedAssetId,\n        /// The path of the second cached scene.\n        path: Option<AssetPath<'static>>,\n    },\n    /// Caused when attempting to include a cached scene when a [`ResolvedScene`] already has [`Template`]s or related scenes.\n    #[error(\"Attempted to include cached scene (id {id:?}, path: {path:?}), but the resolved scene already has templates. For correctness, the cached scene should always be included first.\")]\n    LateCached {\n        /// The asset id of the cached scene that was included late.\n        id: UntypedAssetId,\n        /// The path of the cached scene that was included late.\n        path: Option<AssetPath<'static>>,\n    },\n}\n\n/// An error produced when applying a [`ResolvedScene`].\n#[derive(Error, Debug)]\npub enum ApplySceneError {\n    /// Caused when a [`Template`] fails to build\n    #[error(\"Failed to build a Template in the current Scene: {0}\")]\n    TemplateBuildError(BevyError),\n    /// Caused when the cached [`ResolvedScene`] fails to apply a [`ResolvedScene`].\n    #[error(\"Failed to apply the cached Scene (asset path: \\\"{cached:?}\\\"): {error}\")]\n    CachedSceneApplyError {\n        /// The asset path of the cached scene that failed to apply.","sourceCodeStart":582,"sourceCodeEnd":618,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_scene/src/resolved_scene.rs#L582-L618","documentation":"Runtime error returned by ResolvedScene::include_cached. For correctness the cached scene must be included before any Templates or related scenes are added to the ResolvedScene, because duplicate-template skipping and layering are computed relative to the cached scene. Including it late returns CachedSceneError::LateCached with the late asset's id and path.","triggerScenarios":"Adding templates or relationship scenes to a ResolvedScene (e.g. by resolving scene content that produces them) and only afterwards calling include_cached. include_cached checks self.cached is unset AND that templates/related scenes are empty; non-empty state yields LateCached.","commonSituations":"Custom Scene::resolve implementations that build content first and append the cached include at the end; refactoring that moves the include_cached call; manual ResolvedScene construction in tests.","solutions":["Call include_cached as the very first operation on the ResolvedScene, before any content that adds templates or related scenes","In a custom Scene::resolve impl, include the cached scene before resolving the rest of the BSN content","If you no longer need caching for this scene, skip include_cached entirely and resolve everything normally"],"exampleFix":"// before\nimpl Scene for MyScene {\n    fn resolve(self, ctx: &mut ResolveContext) -> Result<ResolvedScene> {\n        let mut resolved = self.inner_bsn.resolve(ctx)?; // adds templates first\n        resolved.include_cached(self.cached)?;           // LateCached\n        Ok(resolved)\n    }\n}\n\n// after\nimpl Scene for MyScene {\n    fn resolve(self, ctx: &mut ResolveContext) -> Result<ResolvedScene> {\n        let mut resolved = ResolvedScene::default();\n        resolved.include_cached(self.cached)?; // cached first\n        self.inner_bsn.resolve_into(ctx, &mut resolved)?;\n        Ok(resolved)\n    }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if let Err(CachedSceneError::LateCached { id, path }) = resolved.include_cached(handle) {\n    // rebuild the ResolvedScene from scratch, including the cached scene FIRST\n}","preventionTips":["Make include_cached the first mutation on any ResolvedScene you build by hand","In custom Scene::resolve impls, include the cached patch before resolving BSN content"],"tags":["bevy","scene","caching","ordering","runtime"],"backgroundTag":"call-order-violation","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}