Allow for Resource - Component relationships
- 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 want a Resource to store an entity where it would not make sense to do so for components.
```rust
// It wouldn't make sense for this to be a component as there can only be one.
#[derive(Resource)]
pub struct CurrentPlayer(Entity);
pub struct Player;
```
Currently there is no way to ensure that the entity is valid such as in the case of Component relationships.
## What solution would you like?
Allow resources to be specified in relationships
```rust
#[derive(Resource)]
#[relationship_target(relationship = Player)]
pub struct CurrentPlayer(Entity);
#[derive(Component)]
#[relationship(relationship_target = CurrentPlayer)]
pub struct Player(Entity);
```
## What alternative(s) have you considered?
Same as before but check if the entity is valid each time it is used.
Contributor guide
Research direction
Review the existing Component relationship implementation and Resource derive or registration paths to determine where relationship targets are validated. Confirm the desired behavior with a focused test covering the CurrentPlayer and Player example, including invalid-entity handling, and consider the alternative of checking validity whenever the resource is used.
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
- 35/100