How to get component/components from a particular entity?
- Ngôn ngữ chính
- Rust
- Star
- 1.7k
- Fork
- 140
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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!
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Đánh giá
Issue này chưa được đánh giá.