bevyengine / bevyengine/bevy

Add inheritance to required Components

Open
#18,854 0 comments 0 reactions 0 assignees View on GitHub
A-ECS C-Feature S-Needs-Design 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?

Currently if I have a base component that requires a Node and another component that is intended to be used in conjunction with that base component I have to redefine the Node in order to modify the behaviour.

```rust
#[derive(Component)]
#[require(
Node {
width: Val::Percent(100.),
justify_self: JustifySelf::Center,
..Default::default()
}
)]
pub struct PersonDisplay;

#[derive(Component)]
#[require(
Node {
width: Val::Percent(100.), // Both of these
justify_self: JustifySelf::Center, // need to be redefined
flex_direction: FlexDirection::Column, // To add this
..Default::default()
},
PersonDisplay,
)]
pub struct SoldierDisplay;

commands.spawn((PersonDisplay, Name::new("Random Joe")));
commands.spawn((SoldierDisplay, Name::new("Main character")));
```

Obviously this example is quite simple, but with more complex components it can become a bit of an issue.

## What solution would you like?

Some form of inheritance for requirements. I have no idea how this would be done but I wanted bring it up in case anyone had any ideas.

## What alternative(s) have you considered?

Creating a constant and using ..CONSTANT_COMPONENT where needed, but not every component is const friendly

Doing it the way shown, but that can be quite tedious with complicated components, especially if you're just changing one thing.

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.