Skip to content

Conversation

Trashtalk217
Copy link
Contributor

Objective

Many tests currently check against entity_count() in order to see if the absolute number of entities are where they expect it to be. This is not a very robust of doing it, as we're adding more internal entities (#20204).

Solution

Replace entity_count() by a relevant query. We also change iter_entities to filter out Internal entities by default. I don't know if this is the right approach, because unlike default query filters, there are very few escape hatches for users who do want to iterate through all entities, including the internal ones.

I guess you could just make a query.

Actually, why isn't iter_entities just a query?

Testing

I added a world.spawn(Internal) during world bootstrap and most tests succeeded still.

@Trashtalk217 Trashtalk217 added A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change C-Testing A change that impacts how we test Bevy or how users test their apps labels Jul 22, 2025
@Trashtalk217 Trashtalk217 requested a review from chescock July 22, 2025 19:18
// SAFETY: `&self` gives read access to the entire world.
unsafe { EntityRef::new(cell) }
})
.filter(|e| !e.contains::<Internal>())
Copy link
Member

Choose a reason for hiding this comment

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

Actually, let's leave this change out of this PR.

assert_eq!(world.query::<&A>().query(&world).count(), 1);
assert_eq!(
world
.query_filtered::<&Observer, Allows<Internal>>()
Copy link
Contributor

Choose a reason for hiding this comment

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

Huh, it's unfortunate that we need Allows<Internal> in order to query Observer. As a follow-up, we may want to consider expanding the rule for allowing filters to account for required components so that mentioning Observer disables the Internal filter. I don't know whether it's possible to do that efficiently, though.

@alice-i-cecile alice-i-cecile self-requested a review July 23, 2025 18:28
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jul 23, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jul 23, 2025
Merged via the queue into bevyengine:main with commit 8506568 Jul 23, 2025
34 checks passed
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-Code-Quality A section of code that is hard to understand or change C-Testing A change that impacts how we test Bevy or how users test their apps S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants