{"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":271,"sourceCode":"            // PERF: do we really need this fork here?\n            let path = input.fork().parse::<Path>()?;\n            match PathType::new(&path) {\n                PathType::Type | PathType::Enum => {\n                    // Scene components are parsed before this if an @ is found.\n                    // If this path is hit, that means it wasn't prefixed by @\n                    return Err(syn::Error::new(\n                        path.span(),\n                        format!(\n                            \"Scene component {} needs to be prefixed by '@'\",\n                            path_to_string(&path),\n                        ),\n                    ));\n                }\n                PathType::Function | PathType::TypeFunction => {\n                    let path = input.parse::<Path>()?;\n                    let args = input.parse::<BsnFnArgs>()?;\n                    if !args.0.is_empty() {\n                        err_if_cached(\"Cannot cache Scene function with arguments\")?;\n                    }\n                    BsnScene::Fn(BsnSceneFn { path, args })\n                }\n                path_type => {\n                    return Err(syn::Error::new(\n                        path.span(),\n                        format!(\n                            \"Cannot cache path {} of type {:?}\",\n                            path_to_string(&path),\n                            path_type,\n                        ),\n                    ))\n                }\n            }\n        })\n    }\n}\n","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_scene/macros/src/bsn/parse.rs#L253-L289","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":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}