Skip to content
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

How to apply Filter in #[system] with Query<(Entity, &Component)> #277

Closed
nyvs opened this issue Sep 10, 2021 · 3 comments
Closed

How to apply Filter in #[system] with Query<(Entity, &Component)> #277

nyvs opened this issue Sep 10, 2021 · 3 comments

Comments

@nyvs
Copy link

nyvs commented Sep 10, 2021

I know that I can do .filter on a query to add filter arguments, and I know that in a #[system(for_each)]
something like #[filter(maybe_changed::<Position>())] can be added
as described in system proc macro doc

My question is how to do it in this specific configuration:

#[system]
fn beam_array_damage_update(
	targets: &mut Query<(Entity, &Hull, &mut Shield)>, 
	sender: &mut Query<(&BeamArray, &TargetingConsole)>,
	world: &mut SubWorld,
	#[resource] dt: &DeltaTime
) {
	...
}

where parameter targets should have the filter attached to.
I know that Query has a second generic argument F which should probably be used, but how?
Thanks in advance

@nyvs
Copy link
Author

nyvs commented Sep 10, 2021

For the example's sake, lets try to add in a filter that optionally gives me the Shield component

@zedrian
Copy link

zedrian commented Sep 10, 2021

I was not working with filters by myself yet, but as I can see from the #[system] documentation you can only apply filters to a single query (when the system is defined with #[system(for_each)] or #[system(par_for_each)]). The example you provided attempts to work with two different queries at the same time, and the #[system] macro does not have a way to describe filters in that case.

@nyvs
Copy link
Author

nyvs commented Sep 10, 2021

I managed to do it like this:

#[system]
fn beam_array_damage_update(
	targets: &mut Query<(Entity, &mut Hull, Option<&mut Shield>)>, 
	sender: &mut Query<(&BeamArray, &TargetingConsole)>, 
	world: &mut SubWorld,
	#[resource] dt: &DeltaTime
) {
	...
}

I didn't know this was even a thing, until I read this issue and the amethyst docs linked in it.

But as you said for a complex filter my solution probably won't work.

@nyvs nyvs closed this as completed Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants