You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add Has<C>WorldQuery type to replace Option<&C> when checking existence #7811
What problem does this solve or what need does it fill?
I commonly find myself reaching for Option<&C> when I just need to check whether or not a component exists, and then branching on Some versus None.
This works well enough, but:
The access is more restrictive than it needs to be: we request read access, but only actually need existence checking. This limits parallelism, as these systems could run in parallel with mutating systems.
It's less clear to read: the pattern is a bit strange and implicit.
It may be measurably slower.
What solution would you like?
Add a Has<C: Component> type. Implement WorldQuery for this, with no access required.
The item type of each query element should be bool.
What alternative(s) have you considered?
We could do nothing, the eixisting pattern isn't terrible.
We could name this Is<C>: I'm not sure which one is clearer.
It's pretty horrible but Or<(With<T>,)> (when used as query rather than filter) does yield a bool indicating whether the T is present or not. This is kinda weird though since With<T> by itself does not do this.
Activity
SkiFire13 commentedon Feb 24, 2023
It's pretty horrible but
Or<(With<T>,)>(when used as query rather than filter) does yield aboolindicating whether theTis present or not. This is kinda weird though sinceWith<T>by itself does not do this.alice-i-cecile commentedon Feb 24, 2023
Ah right, that's caused by #7680.
BoxyUwU commentedon Feb 24, 2023
Option<With<T>>works which is nicer thanOr<(With<T>,)imoBoxyUwU commentedon Feb 24, 2023
sidenote:
Ordoes not returnboolit returns()Added Has<T> WorldQuery type (bevyengine#8844)
Added Has<T> WorldQuery type (bevyengine#8844)