bevyengine / bevyengine/bevy

Allow required component initialization function to take in a reference to the source component

Open
#17,396 1 comment 7 reactions 0 assignees View on GitHub
A-ECS C-Feature D-Modest S-Needs-Design X-Uncontroversial
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?

In bevy 0.15, a required component can be initialized via a function. Like this

```rust
#[derive(Component)]
#[require(Team(blue_team))]
struct Player {
name: String,
}

fn blue_team() -> Team {
Team::Blue
}
```

It would be great to also support passing the `&Player` reference to the function so I can configure the `Team` value based on what `Player` is. Something like this

```rust
#[derive(Component)]
#[require(Team(team))]
struct Player {
name: String,
}

fn team(player: &Player) -> Team {
if player.name == "..." {
Team::Blue
} else {
Team::Red
}
}
```

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.