Implement WorldQuery
and QueryData
for Mut
#13329
Labels
A-ECS
Entities, components, systems, and events
C-Enhancement
A new feature
D-Straightforward
Simple bug fixes and API improvements, docs, test and examples
X-Contentious
There are nontrivial implications that should be thought through
This is an alternative means of achieving the goals of #12920.
What problem does this solve or what need does it fill?
Currently, the
QueryData
derive macro transforms fields of the type&'static mut T
toMut<'w, T>
when generating the item type for the query. However, the readonly item type continues to use&'w T
as the reference type. This makes it impossible to use change detection on the readonly form of mutable queries.As an example from my code:
What solution would you like?
In #12920, I proposed extending the
QueryData
derive to add adetect_changes
option that would make the derive macro emitRef<T>
instead ofSelf::ReadOnly
when it encounters a&mut T
. I've since realised a simpler way of handling the problem: implementWorldQuery
andQueryData
forMut<T>
directly, setting itsReadOnly
type alias toRef<T>
.I realised this alternate solution during an unstructured discussion in the #ecs_dev Discord channel where some additional questions were brought up.
This would allow for opting into change detection in the readonly form of the query without requiring extension of the derive macro itself, by defining a field as
Mut<'_, T>
instead of&'_ mut T
:What alternative(s) have you considered?
Continue with #12920, which has proven difficult to even begin implementing.
The text was updated successfully, but these errors were encountered: