{"record":{"id":"d7f46fe15a95164f","repo":"bevyengine/bevy","slug":"attempted-to-include-a-second-cached-scene-id-id","errorCode":null,"errorMessage":"Attempted to include a second cached scene (id {id:?}, path: {path:?}), which is not allowed.","messagePattern":"Attempted to include a second cached scene \\(id (.+?), path: (.+?)\\), which is not allowed\\.","errorType":"exception","errorClass":"CachedSceneError","httpStatus":null,"severity":"error","filePath":"crates/bevy_scene/src/resolved_scene.rs","lineNumber":590,"sourceCode":"    }\n}\n\n/// Information about a [`ResolvedScene`]'s cached scene.\n#[derive(Debug)]\npub(crate) struct CachedSceneInfo {\n    /// The handle of the cached scene.\n    pub(crate) handle: Handle<ScenePatch>,\n    /// Template types that occur in _both_ the current scene and its cached scene.\n    /// This is used to skip insertion of these types when applying the cached\n    /// 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","sourceCodeStart":572,"sourceCodeEnd":608,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_scene/src/resolved_scene.rs#L572-L608","documentation":"Runtime error returned by ResolvedScene::include_cached. A ResolvedScene may reference at most one cached scene (a pre-resolved ScenePatch); calling include_cached a second time returns CachedSceneError::MultipleCached with the offending asset id and path. The single-cached-scene limit keeps the cached/resolved layering unambiguous.","triggerScenarios":"Calling resolved.include_cached(handle_a) and then resolved.include_cached(handle_b) on the same ResolvedScene. The first call stores self.cached; the second call sees it already set and returns MultipleCached.","commonSituations":"Composing a scene out of two cached sub-scenes at resolve time; refactoring that adds a second ':' asset include without removing the first; hand-rolled resolve logic that loops over cached handles.","solutions":["Restructure so each ResolvedScene includes exactly one cached scene: nest the second cached scene inside the first cached scene's own BSN/source instead of the outer scene","Drop caching for one of the two sub-scenes and resolve it normally as a related scene","Split the outer scene into two sibling scenes, each with its own cached include"],"exampleFix":"// before\nlet mut resolved = scene.resolve(&ctx)?;\nresolved.include_cached(handle_a.clone())?;\nresolved.include_cached(handle_b)?; // MultipleCached\n\n// after\nlet mut resolved = scene.resolve(&ctx)?;\nresolved.include_cached(handle_a.clone())?;\n// handle_b is included inside the scene that produced handle_a","handlingStrategy":"try-catch","validationCode":"// include_cached returns Result — track inclusion yourself:\nlet mut included_cached = false;\nif !included_cached {\n    resolved.include_cached(handle.clone())?;\n    included_cached = true;\n}","typeGuard":null,"tryCatchPattern":"match resolved.include_cached(handle) {\n    Ok(()) => {}\n    Err(CachedSceneError::MultipleCached { id, path }) => {\n        // merge the extra cached scene upstream instead of including it here\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Design scene composition so each ResolvedScene includes at most one cached scene","Nest additional cached scenes inside the cached scene's own source rather than the outer scene"],"tags":["bevy","scene","caching","runtime","resolved-scene"],"backgroundTag":"duplicate-include-not-allowed","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"}