amethyst / amethyst/legion

How to get component/components from a particular entity?

オープン
#283 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Rust
スター
1.7k
フォーク
140
PR マージ指標
30日以内にマージされた PR はありません

説明

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!

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。