bevyengine/bevy · error · syn::Error

Cannot cache path {} of type {:?}

Error message

Cannot cache path {} of type {:?}

What it means

Compile-time error from the bsn! macro. In scene position the parser resolved the path to a const or type-const (PathType::Const / PathType::TypeConst), which is not a valid scene. The message mentions caching because the checked fork exists to enforce cache constraints, but this arm fires for any const path in scene position, cached or not.

Source

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

                    // 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,
                        ),
                    ))
                }
            }
        })
    }
}

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,

View on GitHub (pinned to 396ca72708)

Solutions

  1. Replace the const with a type implementing Scene used as @Type, or a scene function called as my_fn()
  2. If the const holds a value you need, move it into a component's field value instead of scene position
  3. Remove the entry if it is dead code

Example fix

// before
const MY_SCENE: Handle<ScenePatch> = ...;
bsn! { Children [MY_SCENE] }

// after
bsn! { Children [:"my_scene.scn"] }
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Writing a const path where a scene is expected, e.g. bsn! { Children [MY_SCENE] } where MY_SCENE is a const. The Type/Enum and Function/TypeFunction arms are skipped, the catch-all path_type arm matches Const/TypeConst, and the error is returned.

Common situations: Using a const as an indirection for a scene value; leftover experiment code; assuming any Rust value that implements Scene can be named directly in BSN.

Related errors


AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20). Data as JSON: /api/errors/5b6a5d831f2c394d. Report an issue: GitHub.