Skip to content

Dynamic BSN expressions generate a macro error #24780

Description

@kitsunecafe

Bevy version and features

bevy 0.19.0 with default features

What you did

tried to reproduce the dynamic expression behavior from the scene notation docs

use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .run();
}

#[derive(Component, FromTemplate)]
pub struct Health {
    pub current: u32,
    pub max: u32,
}

#[derive(Component, FromTemplate)]
pub struct Sprite {
    pub image: Handle<Image>,
}

fn enemy(hp: u32, name: &str) -> impl Scene {
    let name_string = name.to_string();
    bsn! {
        #{name}
        Health { current: {hp / 2}, max: hp }
        Sprite { image: {name_string + ".png"} }
    }
}

fn setup(mut commands: Commands) {
    commands.spawn_scene(bsn! { enemy(200, "goblin") });
}

What went wrong

error: expected identifier
  --> src/main.rs:24:10
   |
24 |         #{name}
   |          ^
error: could not compile `dynamic_expr_repro` (bin "dynamic_expr_repro") due to 1 previous error

i'm not sure if this is meant to be a currently supported feature or if it's not yet fully implemented and scheduled for a full release, but it may be helpful if the docs reflected that if so

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ScenesComposing and serializing ECS objectsC-FeatureA new feature, making something new possibleD-MacrosCode that generates Rust codeS-Needs-DesignThis issue requires design work to think about how it would best be accomplished

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions