bevyengine / bevyengine/bevy

Provide easy access to components of targeted entity in observers

Offen
#15,653 9 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
A-ECS C-Feature D-Modest S-Ready-For-Implementation
Vorherrschende Sprache
Rust
Sterne
48.2k
Forks
4.8k
Ø Merge
3 T. 16 Std.
Gemergte PRs (30 T.)
171

Beschreibung

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

When writing observers, it is frequently desirable to be able to access a component on the listener entity, that is, the entity in the trigger event.

Currently there are two ways to do this: either inject a query for all components of that type and pick the one you want; or inject a DeferredWorld, and then look up the component you need on the event's entity.

bevy_mod_picking had convenience methods for injecting components directly. I'd like to see something similar for Bevy.

## What solution would you like?

I'm not sure about naming, but I was thinking of something like:

```rust
entity.observe(trigger: Trigger>, component: ListenerRef);
```
There would be a `ListenerMut` version as well. Alternate names might be `TargetRef`, `TriggerRef`, or `ObserverEntityRef`.

## What alternative(s) have you considered?

For now, I'm using DeferredWorld, as I am unsure about the overhead of injecting a Query.

## Additional context

bevy_mod_picking also provided a means to access the "target" entity and it's components, which was the entity upon which the event was triggered before bubbling, not the entity which handled the event. However, this feature was used rarely (at least by me anyway).

This is also somewhat related to a previous ticket filed by me a long time ago (#11048) - that was rejected (for good reason), but this ticket provides a much more narrowly-scoped variation of the same idea.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit der Durchsicht der bestehenden Observer-, Trigger-, Query- und DeferredWorld-APIs von Bevy und vergleiche anschließend das vorgeschlagene Zugriffsmuster mit dem früheren Issue #11048 und den Convenience-Methoden von bevy_mod_picking. Als erledigt gilt dies, wenn eine abgestimmte API für den unveränderlichen und veränderlichen Zugriff auf Komponenten der Listener-Entität vorliegt und deren Design und Umfang geklärt sind.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
rust
Bereich
game-dev
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.