-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
What problem does this solve or what need does it fill?
Parts of ECS API are missing methods, which have no reason to not exist.
Types that this is most visible on are:
Commands
ChildBuilder
EntityCommands
World
WorldChildBuilder
EntityWorldMut
For example, you cannot use trigger
from ChildBuilder
, but if you spawn an entity and get EntityCommands
you can call EntityCommands::commands()
and then Commands::trigger_targets()
.
fn spawn_trigger<E: Event>(&mut self, event: E) -> EntityCommands {
// Type juggling to get around lifetime downcasting.
// We cannot recover `entity_commands` if we ever drop it.
let mut entity_commands = self.spawn_empty();
let entity = entity_commands.id();
let mut commands = entity_commands.commands();
commands.trigger_targets(event, entity);
entity_commands
}
Proposed solution
This issue proposed the following traits:
a) Spawn
with spawn_empty()
and spawn()
for [1, 2, 4, 5],
b) GetCommands
with commands()
for [1, 2, 3],
c) GetEntity
with entity()
for [1, 2, 4, 5],
d) Trigger
trait trigger()
and trigger_targeted()
for [1, 2, 4, 5],
e) TriggerEntity
with trigger()
for [3, 6],
f) Observe
with observe()
for [1, 3, 4, 6],
g) ModifyEntity
with insert()
and remove()
for [3, 6],
h) WithChildren
with with_children()
for [3, 6].
In general pairs of [1, 4], [2, 5], [3, 6] should share traits.
Now, this is just a proposal.
I want this issue to help decide the actual scope.
Ideally, key traits would make it to 0.14 without introducing breaking changes.
Example implementation for Spawn
What alternative(s) have you considered?
The traits can theoretically be a 3rd part crate, but missing methods need to be added in bevy_ecs
anyways.
Additional context
This is mostly frustrations collected during development of Bevy Jam Template
Relevant discord discussion can be found here