bevyengine / bevyengine/bevy

New Event/Observer API is unfriendly to Entity-like types

Open
#21,384 1 comment 0 reactions 0 assignees View on GitHub
A-ECS C-Usability D-Modest S-Ready-For-Implementation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## What problem does this solve or what need does it fill?

Hello! I maintain the [`moonshine-kind`](https://github.com/Zeenobit/moonshine_kind) crate, which adds the `Instance` type. The new changes for entity events in Bevy 0.17 make hard assumptions that the underlying target is exactly an `Entity` and nothing else.

This makes implementation of newtype wrappers around `Entity` (like `Instance`) very awkward.

For example:

- The `EntityEvent` trait demands a `&mut Entity` access which forces any `Entity`-like struct to provide mutable entity access. This could be avoided if this trait had a `set_event_target` method instead of `event_target_mut`.
- The `EntityEvent` derive macro expects exactly an `Entity` type. In my opinion, it should work with any [`ContainsEntity`](https://docs.rs/bevy/latest/bevy/ecs/entity/trait.ContainsEntity.html) type.
- The `EntityCommands::trigger` method demands an `impl FnOnce(Entity)` constructor function. There should also be a function that lets you just trigger any `EntityEvent` as-is. I don't see the need to *force* the user to pass a constructor instead of the event itself.

## What solution would you like?

- Refactor `EntityEvent::event_target_mut` to `EntityEvent::set_event_target`
- Support `ContainsEntity` on `#[derive(EntityEvent)]`
- Refactor `EntityCommands::trigger` to take an `impl EntityEvent`, and add `trigger_with` as the ctor version. `trigger_with` should also support `ContainsEntity`.

## What alternative(s) have you considered?

N/A

Contributor guide

Open the contributing guide

Research direction

Start by reading the existing EntityEvent trait, the #[derive(EntityEvent)] macro, and EntityCommands::trigger implementation. Trace how event targets and ContainsEntity are handled, then evaluate the proposed direct-event and constructor-based APIs. Done means entity-like targets are supported without breaking existing event behavior, with the relevant repository tests updated.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, game-dev
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.