Skip to content

Enum variant doesn't impl Scene when passed into bsn #24531

@will-hart

Description

@will-hart

Bevy version and features

bevy = { version = "0.19.0-rc.2", default-features = false, features = ["2d", "ui", "bevy_feathers"] }

What you did

I'm trying to create a bsn-based UI function that marks components with an enum variant. The bsn documentation suggests this should be possible. However when passing in an enum variant to the ui function and including it in the bsn macro, I get a compiler error.

What went wrong

I'm trying to create a function that returns a bsn Scene for UI. If I pass in an enum value to the function, it has a compiler error

the trait bound `MyEnum: bevy::prelude::Scene` is not satisfied
the following other types implement trait `bevy::prelude::Scene`:
  ()
  (P0, P1)
  (P0, P1, P2)
  (P0, P1, P2, P3)
  (P0, P1, P2, P3, P4)
  (P0, P1, P2, P3, P4, P5)
  (P0, P1, P2, P3, P4, P5, P6)
  (P0, P1, P2, P3, P4, P5, P6, P7)
and 15 others

I can resolve this by

Additional information

Minimal example.

use bevy::{feathers::FeathersPlugins, prelude::*};

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

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

fn scene_list() -> impl SceneList {
    bsn_list![ui(MyEnum::A)]
}

fn ui(enum_val: MyEnum) -> impl Scene {
    bsn! {
        enum_val
    }
}

Working alternatives:

#[derive(Component, Clone, Default)]
struct MyEnumWrapper(pub MyEnum);

fn ui(enum_val: MyEnum) -> impl Scene {
    bsn! {
        MyEnumWrapper(enum_val)
    }
}

or

// requires explicit `FromTemplate` on `MyEnum`
fn ui(enum_val: MyEnum) -> impl Scene {
    bsn! {
        MyEnum::A
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-BugAn unexpected or incorrect behaviorS-Needs-TriageThis issue needs to be labelled

    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