Skip to content

#[entities] should error when put on a enum variant #19346

@mirsella

Description

@mirsella
Contributor

hello !

Bevy version

bevy 0.16.0

If your bug is rendering-related, copy the adapter info that appears when you run Bevy.

What you did

#[derive(Component)]
pub enum TroopState {
    Idle,
    #[entities] // should error
    Run(Option<Target>),
    #[entities] // should error
    Attack(Target),
}
#[derive(Component)]
pub struct Target {
    #[entities]
    pub entity: Entity,
}

Target is not mapped, this is a footgun, without any warning

What went wrong

the #[entities] should be on the associated type like so Run(#[entities] Option<Target>)
maybe the derive macro can error when the annotation is on the enum variant instead of actual type ?

Activity

added
C-BugAn unexpected or incorrect behavior
S-Needs-TriageThis issue needs to be labelled
on May 23, 2025
added
A-ECSEntities, components, systems, and events
S-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!
X-UncontroversialThis work is generally agreed upon
D-MacrosCode that generates Rust code
and removed
S-Needs-TriageThis issue needs to be labelled
on May 23, 2025
Bleachfuel

Bleachfuel commented on May 26, 2025

@Bleachfuel
Contributor

this is really part of a bigger problem, since the relationship attribute behaves differently, and we would probably also want a different behaviour for when deriving MapEntities, instead of via the component derive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorD-MacrosCode that generates Rust codeS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!X-UncontroversialThis work is generally agreed upon

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @alice-i-cecile@mirsella@Bleachfuel

      Issue actions

        #[entities] should error when put on a enum variant · Issue #19346 · bevyengine/bevy