{"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":623,"sourceCode":"        /// 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.\n    #[error(\"The cached scene (id: {id:?}, path: \\\"{path:?}\\\") has not been resolved yet.\")]\n    UnresolvedCachedScene {\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    },","sourceCodeStart":605,"sourceCodeEnd":641,"githubUrl":"https://github.com/bevyengine/bevy/blob/a62cce8c05ceacd3bd102e678c83e2b42e5dfbe2/crates/bevy_scene/src/resolved_scene.rs#L605-L641","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":"a62cce8c05ceacd3bd102e678c83e2b42e5dfbe2","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}