{"record":{"id":"19bb2604f903717b","repo":"bevyengine/bevy","slug":"failed-to-build-a-template-in-the-current-scene","errorCode":null,"errorMessage":"Failed to build a Template in the current Scene: {0}","messagePattern":"Failed to build a Template in the current Scene: (.+?)","errorType":"exception","errorClass":"ApplySceneError","httpStatus":null,"severity":"error","filePath":"crates/bevy_scene/src/resolved_scene.rs","lineNumber":613,"sourceCode":"        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.\n        cached: Option<AssetPath<'static>>,\n        /// The error that occurred while applying the cached scene.\n        error: Box<ApplySceneError>,\n    },\n    /// Caused when an cached scene is not present.\n    #[error(\"The cached scene (id: {id:?}, path: \\\"{path:?}\\\") does not exist.\")]\n    MissingCachedScene {\n        /// The path of the cached scene.\n        path: Option<AssetPath<'static>>,\n        /// The asset id of the cached scene.\n        id: AssetId<ScenePatch>,\n    },\n    /// Caused when an cached scene has not been resolved yet.","sourceCodeStart":595,"sourceCodeEnd":631,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_scene/src/resolved_scene.rs#L595-L631","documentation":"Variant of ApplySceneError returned while spawning or applying a ResolvedScene. One of the Templates in the scene (entity templates, component templates, or entity-reference templates produced by BSN) failed to build, and the underlying BevyError is wrapped in TemplateBuildError.","triggerScenarios":"Calling resolved.spawn(world) or resolved.apply(entity, ...) when a Template cannot construct its component/entity — for example an entity reference #Name that resolves to nothing, or a template whose inputs are inconsistent at apply time.","commonSituations":"BSN scenes referencing #Entity names that were removed or renamed; templates whose required data is missing at spawn time; partially-built ResolvedScenes produced by custom resolve logic.","solutions":["Inspect the inner BevyError (the {0} payload) — it names the exact template and failure reason","Fix the BSN source so every #Name reference points to an entity declared in the same scope","If building templates from code, validate template inputs before adding them to the ResolvedScene"],"exampleFix":"// before\nbsn! { #Target ChildOf(#Missing) } // #Missing never declared\n\n// after\nbsn! {\n  #Parent\n  Children [\n    #Target ChildOf(#Parent)\n  ]\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match resolved.spawn(&mut world) {\n    Err(SpawnSceneError::ApplySceneError(ApplySceneError::TemplateBuildError(inner))) => {\n        error!(\"template build failed: {inner}\");\n    }\n    other => { /* ... */ }\n}","preventionTips":["Validate every #Name entity reference in BSN resolves to a declared entity in the same scope","Log the inner BevyError — it names the exact failing template"],"tags":["bevy","scene","template","spawn","runtime"],"backgroundTag":"template-build-failed","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"}