bevy
bevy copied to clipboard
Inconsistent API between observers and commands for entity-targetting
Global command vs event:
commands.add(command);
commands.trigger(event);
Entity-local command vs event:
commands.spawn(bundle).add(entity_command).set_parent(parent);
{
let entity = commands.spawn(bundle).id();
commands.trigger_targets(event, entity);
commands.entity(entity)
}.set_parent(parent);
Or with a more ergonomic API (https://github.com/bevyengine/bevy/issues/14233):
commands.spawn(bundle).add(entity_command).set_parent(parent);
commands.spawn(bundle).trigger(event).set_parent(parent);
The difference remains that commands statically distinguish Command and EntityCommand, while events only have Event, with observers having to determine at runtime whether their Trigger includes an entity (currently that entails checking trigger.entity() == Entity::PLACEHOLDER, see https://github.com/bevyengine/bevy/issues/14236).