Skip to content

Storing extra data at relationship components is too easily lost #19589

Open
@urben1680

Description

@urben1680

You are able to store extra data at relationships like this:

#[derive(Component)]
#[relationship(relationship_target = Parent)]
pub struct Child {
    #[relationship]
    parent: Entity,
    pub data: u8, // Relationship data
}

#[derive(Component)]
#[relationship_target(relationship = Child)]
pub struct Parent {
    #[relationship]
    children: Vec<Entity>,
    pub data: u8, // RelationshipTarget data
}

The data is initialized with Default but can be later modified by the user.

However, it can easily happen to lose the data and have it reset to it's default value. Because of this, the user cannot rely on the value to be preserved unless the relationship remains untouched from then on.

In the following I try to maintain a list of ways where I've seen this can happen. Please help me by pointing out what I forgot, or add to it yourself if you are a maintainer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions