Skip to content

Track multiple Relationship types on a single RelationshipTarget component #19045

Open
@Freyja-moth

Description

@Freyja-moth

What problem does this solve or what need does it fill?

There may be times where we might want an entity to have multiple relationships pointing to it (which I have recently encountered) however currently the only way to do this is to define two components for each relationship we want to add.

What solution would you like?

#[derive(Component)]
#[relationship_target]
pub struct Army {
    #[relationship = Unit]
    units: Vec<Entity>,
    #[relationship = Commander]
    commander: Entity
}

#[derive(Component)]
#[relationship(relationship_target = Army)]
pub struct Commander(Entity);

#[derive(Component)]
#[relationship(relationship_target = Army)]
pub struct Unit(Entity);

If this is done it may be a good idea to allow Option as a relationship target to allow for the case that there is no commander, while the army still exists.

What alternative(s) have you considered?

The current solution, however this can get quickly verbose when you consider two or more relationships

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleS-Needs-DesignThis issue requires design work to think about how it would best be accomplishedX-ControversialThere is active debate or serious implications around merging this PR

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions