bevyengine / bevyengine/bevy

Provide easy access to components of targeted entity in observers

Abierto
#15,653 9 comentarios 1 reacción 0 asignados Ver en GitHub
A-ECS C-Feature D-Modest S-Ready-For-Implementation
Lenguaje dominante
Rust
Estrellas
48.2k
Forks
4.8k
Merge medio
3 d 16 h
PR fusionados (30 d)
171

Descripción

## 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.

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Comienza revisando las APIs existentes de Observer, Trigger, Query y DeferredWorld de Bevy, y luego compara el patrón de acceso propuesto con el issue anterior #11048 y los métodos de conveniencia de bevy_mod_picking. Se considerará completado cuando exista una API acordada para el acceso inmutable y mutable a los componentes de la entidad listener, con su diseño y alcance resueltos.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
rust
Área
game-dev
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.