bevyengine / bevyengine/bevy

Support Many-to-Many relationships

Open
#18,121 5 comments 13 reactions 0 assignees View on GitHub
A-ECS C-Usability D-Complex S-Ready-For-Implementation X-Contentious
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

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

Relationships currently support `1-N` relation types, and there's an open PR for `1-1` relationships (#18087). `N-M` relationships are not supported at this moment, but they should be for maximum flexibility. For in-engine use cases, `N-M` relations are required in order to make observers use relations (a single observer can observe multiple entities, and a single entity can be observed by multiple observers).

## What solution would you like?

Support the definition of `N-M` relationships, where this (or something similar) compiles:

```rust
#[derive(Component)]
#[relationship(relationship_target = Observing)]
pub struct ObservedBy(Vec);

#[derive(Component, Default)]
#[relationship_target(relationship = ObservedBy)]
pub struct Observing(Vec);
```

## What alternative(s) have you considered?

As a workaround, `N-M` can be simulated with `1-N` relationships connected via a junction entity a la SQL.

## Additional context

My [relations experiment](https://github.com/EvergreenNest/evergreen_relations) supports `N-M` relationships, which was the primary motivator for making the crate in the first place.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.