Skip to content

Commit bee25be

Browse files
Add release notes for default query filters and entity disabling (#2030)
1 parent c428341 commit bee25be

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed
Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
<!-- Add DefaultQueryFilters -->
2-
<!-- https://github.com/bevyengine/bevy/pull/13120 -->
1+
How would go about marking an entity as disabled in an ECS: unseen-by-default and uninteractable?
2+
Simply deleting it is definitely reliable, but it's relatively expensive, throws away the data, and makes it hard to enable the entity again.
3+
You could move it into a shadow [`World`], but that's esoteric, expensive, and makes it challenging to fetch any data off of it and pass it back into the main [`World`].
34

4-
<!-- TODO -->
5+
What about adding a simple marker component? That seems easy enough: make a unit struct, insert it, and then use `Without<Disabled>` in all of the relevant queries!
6+
7+
While that approach works at first, it quickly becomes frustrating. Did you forget to add the boilerplate somewhere?
8+
Do you vendor all of your dependencies and change their queries too? What if you're making a library? Do all of *your* users need to remember to filter out disabled entities too?
9+
10+
Conceptually though, this seems like the right idea: simply hide the entity from queries and systems that aren't looking for it.
11+
To make this pattern less frustrating Bevy 0.16 introduces the idea of **default query filters**.
12+
13+
These do what they say on the tin: every query will act as if they have a `Without<Disabled>` filter, unless they explicitly mention [`Disabled`] (generally via a `With<Disabled>` or `Option<&Disabled>` argument).
14+
Because this machinery was already built, Bevy allows users (and libraries) to define their own disabling components,
15+
which can be registered via [`App::register_disabling_component`].
16+
Having multiple distinct disabling components can be useful if you want each form of disabling to have its own semantics (or custom behavior!): you might use this feature for hiding networked entities, freezing entities in an off-screen chunk, creating a collection of prefab entities loaded and ready to spawn or something else entirely.
17+
18+
To disable or enable an entity, simply remove or add the disabling component of your choice. It's that easy!
19+
Note that for maximum control and explicitness, only the entities that you directly add disabling components to are disabled: their children or other related entities are not automatically disabled!
20+
This can lead to strange bugs, so in most cases, you should either be careful to call [`Commands::insert_recursive`] and [`Commands::remove_recursive`] or add a hook or observer to get automatic hierarchy-aware disabling.
21+
22+
[`World`]: https://dev-docs.bevyengine.org/bevy/ecs/prelude/struct.World.html
23+
[`Disabled`]: https://dev-docs.bevyengine.org/bevy/ecs/entity_disabling/struct.Disabled.html
24+
[`Commands::insert_recursive`]: https://dev-docs.bevyengine.org/bevy/prelude/struct.EntityCommands.html#method.insert_recursive
25+
[`Commands::remove_recursive`]: https://dev-docs.bevyengine.org/bevy/prelude/struct.EntityCommands.html#method.remove_recursive

release-content/0.16/release-notes/_release-notes.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ prs = [16132, 16826]
2929
file_name = "16132_Entity_cloning.md"
3030

3131
[[release_notes]]
32-
title = "Add DefaultQueryFilters"
33-
authors = ["@NiseVoid"]
32+
title = "Entity disabling via default query filters"
33+
authors = ["@NiseVoid", "@alice-i-cecile"]
3434
contributors = []
35-
prs = [13120]
35+
prs = [13120, 17514, 17768]
3636
file_name = "13120_Add_DefaultQueryFilters.md"
3737

3838
[[release_notes]]

0 commit comments

Comments
 (0)