You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot easily spawn an entity with one component #607
If I try spawning an entity with just one component, I get the following error:
error[E0277]: the trait bound `Pawn: bevy::bevy_ecs::DynamicBundle` is not satisfied
--> examples/balls.rs:69:20
|
69 | commands.spawn(Pawn { controller: 1 }).with(Ball {
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `bevy::bevy_ecs::DynamicBundle` is not implemented for `Pawn`
I need to spawn a one element tuple:
commands.spawn((Pawn{controller:1},)).with(Ball{
There is no way of coming up to that solution from the error message.
Bevy's selling point is ECS ergonomics - i think this needs to be fixed.
Reacted by Bauxitedev, Sven-Hendrik Haase, Ross Hays, Dmitriy Shmilo, Marvin Sextro and whale9490
Since there are multiple components in your example, could do .spawn((Pawn, Ball)), but I understand there can be a preference to use the methods since it allows quickly commenting out withs. spawn(()).with(component) works but also isn't entirely ergonomic.
We could add a method like Commands::spawn_with(&mut self, component: impl Component), and then spawn could be renamed to spawn_with_bundle for clarity.
To add spawn_with to your app today, an option is to use a function or add this to an extension trait.
Note: make sure during bevy upgrades that any new inherent methods on Commands don't shadow your extension methods' names since Rust will prefer the inherent method first.
Yeah there is unfortunately no way to make spawn() work with both tuples and individual components (because a component could be, itself a tuple). So they are ambiguous to rustc.
I like @memoryruins idea to make "bundles" a clear part of the api and to add a new api for spawning single components.
This sounds like a fun change to make, so I figured I'd give it a shot. Please take a look at #611 and let me know if I'm going in the right direction (naming is hard).
Activity
memoryruins commentedon Sep 30, 2020
Since there are multiple components in your example, could do
.spawn((Pawn, Ball)), but I understand there can be a preference to use the methods since it allows quickly commenting outwiths.spawn(()).with(component)works but also isn't entirely ergonomic.We could add a method like
Commands::spawn_with(&mut self, component: impl Component), and thenspawncould be renamed tospawn_with_bundlefor clarity.To add
spawn_withto your app today, an option is to use a function or add this to an extension trait.Note: make sure during bevy upgrades that any new inherent methods on
Commandsdon't shadow your extension methods' names since Rust will prefer the inherent method first.cart commentedon Oct 1, 2020
Yeah there is unfortunately no way to make spawn() work with both tuples and individual components (because a component could be, itself a tuple). So they are ambiguous to rustc.
I like @memoryruins idea to make "bundles" a clear part of the api and to add a new api for spawning single components.
smokku commentedon Oct 1, 2020
Thank you for the explanation.
I also like the idea of making the bundle spawning more clear. "Explicit is better than implicit."
BTW, I didn't know you can extend an imported type like that. Thank you @memoryruins for this example. :-)
CleanCut commentedon Oct 1, 2020
This sounds like a fun change to make, so I figured I'd give it a shot. Please take a look at #611 and let me know if I'm going in the right direction (naming is hard).
alice-i-cecile commentedon Jan 16, 2021
This is fixed now that #611 is merged in and can be closed.
memoryruins commentedon Jan 16, 2021
#611 was closed, not merged. The discussion in it contains good points to consider when this issue is picked back up again.
alice-i-cecile commentedon Mar 7, 2021
This should be greatly improved or closed by #1562.
ledyba commentedon Apr 1, 2021
#1703 (seems improved version of #1562 ) has been closed.
So was this issue solved?
alice-i-cecile commentedon Apr 1, 2021
Yes, you can now do:
No weird tuple shenanigans needed.