Add trait ComponentConstructor
- 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?
For rapier and avian, Collider is not implemented with `Reflect`. We cannot use extra properties in GLFT to reflect to create components.
Can we add a ComponentConstructor or something else to create a component from a reflectable constructor.
## What solution would you like?
Allow Component convert from another reflectable type
```rust
#[derive(Component)]
struct Foo {
....
}
impl Foo {
pub fn new_a (...) { ... }
pub fn new_b (...) { ... }
}
#[derive(Reflect, ComponentConstructor)]
enum FooConstructor {
A( ... ),
B( ... ),
}
impl ComponentConstructor for FooConstructor {
type C = Foo;
pub fn to_component(self) -> C {
....
}
}
....
// for spawn
commands.spawn(( FooConstructor::A( .... ), ))
// should same with
commands.spawn(( Foo::new_a( ... ), ))
```
## What alternative(s) have you considered?
For avian, they use https://github.com/Jondolf/avian/blob/39a7480cd1915bc5266aa8ebd3c3436d4d0568b0/src/collision/collider/backend.rs#L358C4-L358C30 to convert Constructor to Component.
Contributor guide
Assessment
This issue has not been assessed yet.