-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Entity labeling #11897
Comments
I agree, I've been thinking about tagging / labeling entities lately and it makes sense. |
Seems like a duplicate of #6556 . I also made a crate for this which is linked to in this issue but it hasn't been updated since 0.10. if you want, you can fork or pr tho |
Can't you create a marker component and use #[derive(Component)]
struct Player;
#[derive(Component)]
struct Enemy;
fn spawn_system(
mut commands: Commands,
) {
commands.spawn((transform, health, Player));
commands.spawn((transform, health, Enemy));
}
fn my_system(
player: Query<(&Transform, &Health), With<Player>>,
enemy: Query<(&Transform, &Health), With<Enemy>>,
) {
let (p_transform, p_health) = player.single();
let (e_transform, e_health) = enemy.single();
} If you don't want to use marker components, you could make a |
Yeah, I think this is functionally a duplicate. Not opposed, but just want to collect discussion. |
yes, but you need to create 2 queries, this example is simple but what if you had more complicated case? |
@Itsnotdone when there only exists one "player" or "enemy" at the same time, you can use entity markers. When there are multiple you won't get around multiple queries. Also note that the queries mustn't overlap, so you must add |
Not exactly, because in this proposal you need to add every tag to query which you are requesting, thats horrible if you have more tags (or am i wrong?) |
yes that's because it initially was meant to provide some parallelism hints but that wasn't done. |
Never the less, as alice says you are welcome to contribute your ideas to the open issue. |
What problem does this solve or what need does it fill?
Easier iterating over entities, you dont need to create multiple queries to distinguish entities. Currently you need to create two queries to get (for example) Enemy and Player, also it may be useful for future editor
What solution would you like?
Something like:
What alternative(s) have you considered?
Storing the Entity ID and using query.get(entity)
Additional context
The text was updated successfully, but these errors were encountered: