bevyengine/bevy · error · syn::Error

Cannot cache Scene function with arguments

Error message

Cannot cache Scene function with arguments

What it means

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.

Solutions

  1. Remove the ':' prefix so the scene function runs uncached: my_scene_fn(10)
  2. Keep the ':' only if the function genuinely takes no arguments: :my_scene_fn()
  3. Replace the parameterized function with a type implementing Scene plus fields, written as @Type { ... } (though note fields also cannot be cached)

Example fix

// before
bsn! { :spawn_tree(5) }

// after
bsn! { spawn_tree(5) }
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of bevyengine/bevy@a62cce8c05 (2026-08-20). Data as JSON: /api/errors/695781af62611ca5. Report an issue: GitHub.

Appendix: source

Thrown at crates/bevy_scene/macros/src/bsn/parse.rs:315

                PathType::Type | PathType::Enum => {
                    BsnScene::SceneComponent(input.parse::<BsnType>()?)
                }
                PathType::Function | PathType::TypeFunction => {
                    let path = input.parse::<Path>()?;
                    if path_type == PathType::Function
                        && path.segments.len() == 1
                        && !input.peek(Paren)
                    {
                        BsnScene::Expression(path.to_token_stream())
                    } else {
                        let args = input.parse::<BsnFnArgs>()?;
                        BsnScene::Fn(BsnSceneFn { path, args })
                    }
                }
                path_type => {
                    return Err(syn::Error::new(
                        path.span(),
                        format!(
                            "Scenes with path {} of type {:?} are not supported",
                            path_to_string(&path),
                            path_type,
                        ),
                    ))
                }
            }
        })
    }
}

impl Parse for BsnType {
    fn parse(input: ParseStream) -> Result<Self> {
        let mut path = input.parse::<Path>()?;
        let enum_variant = match PathType::new(&path) {
            PathType::Type => None,
            PathType::Enum | PathType::TypeConst => take_last_path_ident(&mut path),
            PathType::Function | PathType::TypeFunction => {

View on GitHub (pinned to a62cce8c05)