Skip to content

Relationship annotation does not allow more than additional field #18466

@jesse3339

Description

@jesse3339

Bevy version

0.16.0-rc.1

What you did

Added more than one non-relationship annotated field.

//child entity
#[derive(Component, Debug)] // <-- error here
#[relationship(relationship_target = ModifierCollectionRefs)]
pub struct ModifierInstance {
    #[relationship]
    pub collection_owning_entity: Entity,
    pub tag: ValueTag,
    pub source_context: ModifierContext,
    pub target_context: Option<ModifierContext>,
    pub value: ModifierValue
}

// parent entity
#[derive(Component, Debug, Default)]
#[relationship_target(relationship = ModifierInstance)]
pub struct ModifierCollectionRefs {
    modifiers: Vec<Entity>
}

What went wrong

error: expected identifier, found `,`
  --> src/modifiers.rs:32:10
   |
32 | #[derive(Component, Debug)]
   |          ^^^^^^^^^
   |          |
   |          expected identifier
   |          while parsing this struct

I was expecting to be able to add more than one other non-relationship field on a relational component, however I cannot compile.

Additional information

Workarounds:

  • extract out other fields into another component. However, since I am not sure how to implement Default for relational components, in which case it is not obvious what the default parent should be, I have to couple the relational component to the data (that implements default), which may actually be the correct way to do it? Idk.

Assumed issue:
Relationship macro or relationship annotated field does not support more than one field in the related struct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorD-MacrosCode that generates Rust codeD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions