amethyst / amethyst/legion

How to get component/components from a particular entity?

Abierto
#283 2 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Rust
Estrellas
1.7k
Forks
140
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

I browsed the docs, but I could not figure out for myself.

I know we have queries that will let us go trough all the components of type `C` from a world, but is there a way to get a component of type C from a particular entity?

Actually I'm interested in getting references `&T` and `&mut T` to the component attached to a particular entity.

I tried to do something like:
```rust
pub fn with_component(&self) -> Option<&T> {
if let Ok(entry) = self.world.borrow_mut().entry_ref(self.entity) {
if let Ok(component) = entry.get_component::() {
return Some(component);
}
}

None
}
```

but then it complained that the reference I return does not live long enough.

I want something like this because I just want `&T` or `&mut T` to the component, why do we need to deal with that `entry` step? :-(

Thank you!

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.