-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Support using FilteredResources with ReflectResource. #15624
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
Support using FilteredResources with ReflectResource. #15624
Conversation
…rces-ReflectResource
…rces-ReflectResource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, but I'm not super confident in my ability to judge this code.
| /// Function pointer implementing [`ReflectResource::reflect()`]. | ||
| pub reflect: fn(&World) -> Option<&dyn Reflect>, | ||
| pub reflect: for<'w> fn(FilteredResources<'w, '_>) -> Option<&'w dyn Reflect>, | ||
| /// Function pointer implementing [`ReflectResource::reflect_mut()`]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be cool if this could be a static assertion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite sure what you want asserted? I was trying to copy the style of the existing comments, and I think that's meant to be read as "ReflectResource::reflect_mut() invokes this function pointer".
…rces-ReflectResource # Conflicts: # crates/bevy_ecs/src/system/builder.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Objective
Support accessing resources using reflection when using
FilteredResourcesin a dynamic system. This is similar to how components can be queried using reflection when usingFilteredEntityRef|Mut.Solution
Change
ReflectResourcefrom taking&Worldand&mut Worldto takingimpl Into<FilteredResources>andimpl Into<FilteredResourcesMut>, similar to howReflectComponenttakesimpl Into<FilteredEntityRef>andimpl Into<FilteredEntityMut>. There areFromimpls that ensure code passing&Worldand&mut Worldcontinues to work as before.Migration Guide
If you are manually creating a
ReflectComponentFnsstruct, thereflectfunction now takesFilteredResourcesinstead&World, and there is a newreflect_mutfunction that takesFilteredResourcesMut.