bevyengine / bevyengine/bevy

Dynamic BSN expressions generate a macro error

Open
#24,780 3 comments 0 reactions 0 assignees View on GitHub
A-Scenes C-Feature D-Macros S-Needs-Design
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## 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](https://docs.rs/bevy/latest/bevy/scene/index.html#using-dynamic-expressions-in-scenes)

```rs
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,
}

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

Contributor guide

Open the contributing guide

Research direction

Start with the dynamic expressions section of the scene notation docs and the minimal Rust reproduction shown in the issue. Compare the documented bsn! syntax with the macro's accepted input, then verify the result by rerunning the reproduction; done means the behavior is supported as documented or the documentation clearly states the limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.