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.

Source

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

            // PERF: do we really need this fork here?
            let path = input.fork().parse::<Path>()?;
            match PathType::new(&path) {
                PathType::Type | PathType::Enum => {
                    // Scene components are parsed before this if an @ is found.
                    // If this path is hit, that means it wasn't prefixed by @
                    return Err(syn::Error::new(
                        path.span(),
                        format!(
                            "Scene component {} needs to be prefixed by '@'",
                            path_to_string(&path),
                        ),
                    ));
                }
                PathType::Function | PathType::TypeFunction => {
                    let path = input.parse::<Path>()?;
                    let args = input.parse::<BsnFnArgs>()?;
                    if !args.0.is_empty() {
                        err_if_cached("Cannot cache Scene function with arguments")?;
                    }
                    BsnScene::Fn(BsnSceneFn { path, args })
                }
                path_type => {
                    return Err(syn::Error::new(
                        path.span(),
                        format!(
                            "Cannot cache path {} of type {:?}",
                            path_to_string(&path),
                            path_type,
                        ),
                    ))
                }
            }
        })
    }
}

View on GitHub (pinned to 396ca72708)

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@396ca72708 (2026-08-20). Data as JSON: /api/errors/695781af62611ca5. Report an issue: GitHub.