Allow limiting the amount of entities in a RelationshipTarget
- 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?
Currently all `RelationshipTargets` are (potentially) infinite in length. However this may not always be a desired behavior (such as with inventories with a limited capacity)
## What solution would you like?
Allow limiting the length of a `RelationshipTarget`
```rust
#[derive(Component)]
// overflow determines what to do when an item is added without space
// - replace_first: replaces the first entity in the vec with the new entity
// - replace_last: replaces the last entity in the vec with the new entity
// - block: doesn't change anything about the relationship target
#[relationship_target(relationship = Item, max_length = 10, overflow(replace_first))]
pub struct Inventory(Vec);
#[derive(Component)]
#[relationship(relationship_target = Inventory)]
pub struct Item(Entity);
```
I'm not certain about this, it does introduce some more complexity with relationships which I'm not certain I like and it may be easy for newcomers to miss which may make it redundant. It also only allows for hard coded lengths which may not be desirable for some.
Perhaps this could be mitigated with a `RelationshipLength` component? I'm not certain.
But I do imagine there are a lot of cases where this might be useful
## What alternative(s) have you considered?
Use observers to check for inserted relationships and enforce size limits.
Contributor guide
Assessment
This issue has not been assessed yet.