bevyengine / bevyengine/bevy

Track multiple `Relationship` types on a single `RelationshipTarget` component

Open
#19,045 4 comments 0 reactions 0 assignees View on GitHub
A-ECS C-Feature S-Needs-Design X-Needs-SME
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## 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?

```rust
#[derive(Component)]
#[relationship_target]
pub struct Army {
#[relationship = Unit]
units: Vec,
#[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

Contributor guide

Open the contributing guide

Research direction

Start by locating Bevy's relationship and relationship-target derive implementations, then inspect how a single target currently handles its relationship type. Compare that behavior with the issue's `Army`, `Unit`, and `Commander` example, including the proposed `Option` case. Done means one `RelationshipTarget` can represent multiple relationship types without defining separate target components, with coverage for the optional target behavior if included.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.