Skip to content
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

Clarify how Query::get_component works #9523

Closed

Conversation

alice-i-cecile
Copy link
Member

Objective

  • Users were confused about the data that Query::get_component can access.

what's the point of the get_component(_mut) methods on Query, do they completely ignore the Q and F generic parameters on the query itself?

(from Discord

Solution

  • Explain that the query is limited to declared component accesses.
  • Also leave a small note about the importance of requesting mutable access.

@alice-i-cecile alice-i-cecile added C-Docs An addition or correction to our documentation A-ECS Entities, components, systems, and events labels Aug 21, 2023
@Aurora2500
Copy link

I think a better example would be great too, since the one used right now is identical to that of the method Query::get, and from my perspective doesn't show what its point is.

Maybe a small change would be to make Character a WorldQuery and have a new Health component be part of this WorldQuery, explaining this relation between the two and how get_component deals with it.

/// In case of a nonexisting entity or mismatched component, a [`QueryComponentError`] is returned instead.
///
/// If the declared access for the provided component is read-only, only an immutable reference will be returned.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's true for get_component_mut, it returns a MissingWriteAccess in that case, there is a doc test for that case: https://docs.rs/bevy/latest/bevy/ecs/system/enum.QueryComponentError.html#variant.MissingWriteAccess

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Docs An addition or correction to our documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants