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.

Source

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

        // and how there doesn't seem to be a need for all the specific `err_if_cached`
        // in later code. But since caching is planned, and will very likely
        // have the limitations which are ensured by the other errors below,
        // this is its own block so its very simple to remove once caching is implemented.
        if !input.peek(LitStr) {
            err_if_cached("Currently, caching is only supported for scene assets. Please remove the ':' prefix for now.")?;
        }

        Ok(if input.peek(LitStr) {
            let path = input.parse::<LitStr>()?;
            if cached.is_none() {
                return Err(syn::Error::new(
                    path.span(),
                    "Cannot use scene assets without caching, please add the ':' prefix.",
                ));
            }
            BsnScene::Asset(path)
        } else if input.peek(Brace) {
            err_if_cached("Cannot cache scene expressions")?;
            BsnScene::Expression(braced_tokens(input)?)
        } else if input.peek(At) {
            input.parse::<At>()?;
            let sc = input.parse::<BsnType>()?;
            if sc.fields.len() > 0 {
                err_if_cached("Cannot cache Scene Components with props/fields")?;
            }
            BsnScene::SceneComponent(sc)
        } else {
            // 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!(

View on GitHub (pinned to 396ca72708)

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