bevyengine/bevy · error · syn::Error

Cannot cache Scene Components with props/fields

Error message

Cannot cache Scene Components with props/fields

What it means

The @-prefixed scene-component form (@MySceneComponent) parses a BsnType; if it has fields/props, err_if_cached rejects it under a ':' cache prefix — only fieldless scene components are cacheable in principle. As with the expression case, the earlier 'caching is only supported for scene assets' check (parse.rs:229-231) intercepts ':' + non-literal first today, so this message is the guard kept for when asset-only caching is relaxed.

Solutions

  1. Remove the ':' prefix from the scene component: @MySceneComponent { field: value }
  2. If you need caching, put the content in a scene asset and load it with :"path.scene" instead

Example fix

// before
bsn!(:@MySceneComponent { speed: 10.0 });

// after
bsn!(@MySceneComponent { speed: 10.0 });
Defensive patterns

Strategy: validation

Validate before calling

// Rule: @SceneComponent forms take no ':' prefix; if the component has
// fields, caching is not an option at all today.

Prevention

When it happens

Trigger: Writing :@MySceneComponent { field: value } — a cached scene component that carries fields (currently surfaced as the 'only scene assets' error due to the earlier check).

Common situations: Marking data-rich scene components as cached; assuming ':' works uniformly across all BSN scene forms.

Related errors


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

Appendix: source

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

    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)
                    {
                        BsnScene::Expression(path.to_token_stream())
                    } else {
                        let args = input.parse::<BsnFnArgs>()?;
                        BsnScene::Fn(BsnSceneFn { path, args })
                    }
                }

View on GitHub (pinned to a62cce8c05)