bevyengine/bevy · error · syn::Error

Cannot cache scene expressions

Error message

Cannot cache scene expressions

What it means

BsnScene::parse handles braced scene expressions ({ ... }) as BsnScene::Expression, and err_if_cached rejects them when a ':' cache prefix was given: inline expressions cannot be cached. Note the source order: the earlier 'only scene assets' check (parse.rs:229-231) fires first for any non-string-literal after ':', so today this specific message is the designated guard for when that earlier restriction is lifted and expression caching is the remaining gap.

Solutions

  1. Remove the ':' from the expression: { scene_expression }
  2. If you want caching, move the expression's content into a scene asset file and reference it as :"path.scene"

Example fix

// before
bsn!(:{ my_built_scene });

// after
bsn!({ my_built_scene });
Defensive patterns

Strategy: validation

Validate before calling

// Rule: braced scene expressions { ... } must be written uncached (no ':').
// If caching is needed, externalize the expression into a .scene asset file.

Prevention

When it happens

Trigger: Writing :{ scene_expression } — a braced expression with the cache prefix — in bsn!/bsn_list! (currently surfaced as the 'only scene assets' error due to the earlier check).

Common situations: Trying to cache the result of a computed/inline scene expression; assuming BSN caching covers everything the macro can express.

Related errors


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

Appendix: source

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

    }
}

custom_punctuation!(TwoMinus, --);

impl Parse for BsnSceneListItem {
    fn parse(input: ParseStream) -> Result<Self> {
        Ok(if input.peek(Brace) {
            let tokens = braced_tokens(input)?;
            BsnSceneListItem::Expression(tokens)
        } else {
            BsnSceneListItem::Scene(input.parse::<Bsn>()?)
        })
    }
}

impl BsnScene {
    fn parse(input: ParseStream) -> Result<Self> {
        Ok(if input.peek(LitStr) {
            let path = input.parse::<LitStr>()?;
            BsnScene::Asset(path)
        } else if input.peek(Brace) {
            BsnScene::Expression(braced_tokens(input)?)
        } else {
            // PERF: do we really need this fork here?
            let path = input.fork().parse::<Path>()?;
            let path_type = PathType::new(&path);
            match path_type {
                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)
                    {

View on GitHub (pinned to a62cce8c05)