How do I port this very generic Query
function to bevy 0.17 ?
#21540
-
So, we have this function in the project, which I'm trying to bring from 0.13 to 0.17 fn query_mut<T: QueryData>(
world: &'_ mut World,
check: impl Fn(&QueryItem<T>) -> bool,
) -> Result<QueryItem<'_, T>, String> {
let mut query = world.query::<T>();
query
.iter_mut(world)
.find(check)
.ok_or_else(|| format!("Could not find obj {}", type_name::<T>()))
} It's not meant to be very efficient, it's mostly used for unit tests and some specific scripting purposes. I'm having a lot of trouble making this function work with the new system where |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I think this is a hard problem to fix, since the new 's lifetime is tied to the local Bevy could potentially add a unsafe trait that would be implemented for QueryData that doesn't return data from the state. Not sure if it would be worth the complexity or not given this niche use case. |
Beta Was this translation helpful? Give feedback.
found out that there is
ReleaseStateQueryData
that allows you to return 'static for the second lifetime if the QueryData allows it. https://docs.rs/bevy/latest/bevy/ecs/query/trait.ReleaseStateQueryData.html