{"record":{"id":"695781af62611ca5","repo":"bevyengine/bevy","slug":"cannot-cache-scene-function-with-arguments","errorCode":null,"errorMessage":"Cannot cache Scene function with arguments","messagePattern":"Cannot cache Scene function with arguments","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"crates/bevy_scene/macros/src/bsn/parse.rs","lineNumber":315,"sourceCode":"                PathType::Type | PathType::Enum => {\n                    BsnScene::SceneComponent(input.parse::<BsnType>()?)\n                }\n                PathType::Function | PathType::TypeFunction => {\n                    let path = input.parse::<Path>()?;\n                    if path_type == PathType::Function\n                        && path.segments.len() == 1\n                        && !input.peek(Paren)\n                    {\n                        BsnScene::Expression(path.to_token_stream())\n                    } else {\n                        let args = input.parse::<BsnFnArgs>()?;\n                        BsnScene::Fn(BsnSceneFn { path, args })\n                    }\n                }\n                path_type => {\n                    return Err(syn::Error::new(\n                        path.span(),\n                        format!(\n                            \"Scenes with path {} of type {:?} are not supported\",\n                            path_to_string(&path),\n                            path_type,\n                        ),\n                    ))\n                }\n            }\n        })\n    }\n}\n\nimpl Parse for BsnType {\n    fn parse(input: ParseStream) -> Result<Self> {\n        let mut path = input.parse::<Path>()?;\n        let enum_variant = match PathType::new(&path) {\n            PathType::Type => None,\n            PathType::Enum | PathType::TypeConst => take_last_path_ident(&mut path),\n            PathType::Function | PathType::TypeFunction => {","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/bevyengine/bevy/blob/a62cce8c05ceacd3bd102e678c83e2b42e5dfbe2/crates/bevy_scene/macros/src/bsn/parse.rs#L297-L333","documentation":"Compile-time error from the bsn! macro. BSN scene caching is opt-in via a leading ':' prefix on a scene entry, but cached scenes must be fully determined at parse time. A scene function call that takes arguments cannot be cached because its arguments would be baked into the cached artifact.","triggerScenarios":"Writing a cached scene function with a non-empty argument list, e.g. bsn! { :my_scene_fn(10) }. The parser sees the ':' (cached), parses the path as a function, parses BsnFnArgs, finds them non-empty, and err_if_cached returns this error pointing at the ':' token.","commonSituations":"Trying to speed up scene instantiation by adding the ':' cache prefix to every scene entry, including parameterized factory functions; assuming function arguments are serialized with the cache.","solutions":["Remove the ':' prefix so the scene function runs uncached: my_scene_fn(10)","Keep the ':' only if the function genuinely takes no arguments: :my_scene_fn()","Replace the parameterized function with a type implementing Scene plus fields, written as @Type { ... } (though note fields also cannot be cached)"],"exampleFix":"// before\nbsn! { :spawn_tree(5) }\n\n// after\nbsn! { spawn_tree(5) }","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use the ':' cache prefix on argument-free scene functions or plain scene asset paths","Remember cached scenes must be fully static: no function args, no component fields, no expressions"],"tags":["bevy","bsn","proc-macro","caching","scene"],"backgroundTag":"rust-macro-parse-error","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"}