bevy_enum_filter
bevy_enum_filter copied to clipboard
Fixed that query.iter().len() is 0 on the first frame.
With the changes in this PR, the marker structs will be registered in the PostStartup
schedule (in addition to the original Update
) allowing for any schedule that follows this to access the query.
One of the things I've noticed is when using this within a query, the query isn't populated immediately.
I think this is due to the Changed
filter.
Consider the following example, that now works:
fn player_movement(mut query: Query<(&mut Transform), With<Enum!(app::Tag::Player)>>) {
let mut transform = query.single_mut();
// Do some mutations here...
}
This is not possible in the original code, and in fact, if we were to just change the body to println!("{}", query.iter_mut().len())
then we'd see the console print the value 0
, before printing a sea of 1
.
Currently we have to implement the code in the following way:
fn player_movement(mut query: Query<(&mut Transform), With<Enum!(app::Tag::Player)>>) {
if query.is_empty() {
return;
}
let mut transform = query.single_mut();
// Do some mutations here...
}