bevyengine / bevyengine/bevy

Enums not working in bsn! macro without explicit FromTemplate derive

Open
#24,469 6 comments 0 reactions 0 assignees View on GitHub
A-Scenes C-Docs 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
`v0.19.0-dev` commit `564eb4fc`
features `["dynamic_linking", "bevy_feathers"]`

## \[Optional\] Relevant system information

rust `1.98.0-nightly (4d1f98451 2026-05-15)`
os `Linux pop-os 6.18.7-76061807-generic #202601231045~1778249322~24.04~b44a3c3 SMP PREEMPT_DYNAMIC Fri M x86_64 x86_64 x86_64 GNU/Linux` (Ubuntu 24.04 based)

## What you did

Describe how you arrived at the problem. If you can, consider providing a code snippet or link.
```rust
use bevy::prelude::*;

#[derive(Component, Clone, Default)]
enum MyEnum {
#[default]
Foo,
Bar,
}

fn gui() -> impl Scene {
bsn! {
MyEnum::Foo
}
}

```
Compile error:
```rust
error[E0599]: no variant, associated function, or constant named `default_foo` found for enum `MyEnum` in the current scope
--> src/bin/bsn_min_repro.rs:13:5
|
4 | enum MyEnum {
| ----------- variant, associated function, or constant `default_foo` not found for this enum
...
13 | bsn! {
| _____^
14 | | MyEnum::Foo
15 | | }
| |_____^ variant, associated function, or constant not found in `MyEnum`
|
= note: this error originates in the macro `bsn` (in Nightly builds, run with -Z macro-backtrace for more info)
```

## What went wrong
The [FromTemplate docs](https://docs.rs/bevy/0.19.0-rc.2/bevy/ecs/prelude/trait.FromTemplate.html) state that
> Both [FromTemplate](https://docs.rs/bevy/0.19.0-rc.2/bevy/prelude/trait.FromTemplate.html) and [Template](https://docs.rs/bevy/0.19.0-rc.2/bevy/prelude/trait.Template.html) are blanket implemented for types that implement [Default](https://doc.rust-lang.org/nightly/core/default/trait.Default.html) and [Clone](https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html), meaning most types you would want to use already have templates.

The [bsn! docs](https://docs.rs/bevy/0.19.0-rc.2/bevy/prelude/macro.bsn.html#defaults-and-patching) state that
> Clone + Default and FromTemplate cannot both be derived on the same type.

The compiler error points to the following in the expanded `bsn!` macro:
```rust
*_node = ::bevy::scene::macro_utils::PathResolveHelper::<
::Template,
>::default_foo();

```

Explicitly deriving `FromTemplate` on `MyEnum` resolved this. Note that this works with or without `Clone + Default`, which contradicts the `bsn!` docs above.
`#[derive(Component, Clone, Default, FromTemplate)]`
`#[derive(Component, FromTemplate)]`

## Additional information

Other information that can be used to further reproduce or isolate the problem.
This commonly includes:

- screenshots
- logs
- theories about what might be going wrong
- workarounds that you used
- links to related bugs, PRs or discussions

Contributor guide

Open the contributing guide

Research direction

Start at the bsn! macro entry point and inspect how enum paths become FromTemplate::Template default_* calls; compare this with the behavior when FromTemplate is explicitly derived. Add regression coverage for an enum using only Clone + Default, then verify that the bsn! example compiles and the documented derive behavior is consistent.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.