Skip to content

Add simple Disabled marker #17514

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

Merged
merged 4 commits into from
Feb 2, 2025

Conversation

NiseVoid
Copy link
Contributor

@NiseVoid NiseVoid commented Jan 23, 2025

Objective

We have default query filters now, but there is no first-party marker for entity disabling yet
Fixes #17458

Solution

Add the marker, cool recursive features and/or potential hook changes should be follow up work

Testing

Added a unit test to check that the new marker is enabled by default

@NiseVoid NiseVoid added the A-ECS Entities, components, systems, and events label Jan 23, 2025
@BenjaminBrienen BenjaminBrienen added C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 23, 2025
@BenjaminBrienen
Copy link
Contributor

I think that this should close that issue. Would you mind fixing the description? :)

@alice-i-cecile alice-i-cecile added this to the 0.16 milestone Jan 24, 2025

let disabled = self.register_component::<Disabled>();
let mut filters = DefaultQueryFilters::default();
filters.set_disabled(disabled);
Copy link
Contributor

@cBournhonesque cBournhonesque Jan 25, 2025

Choose a reason for hiding this comment

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

I'm a bit worried that users might do a
app.init_resource::<DefaultQueryFilters>()

and lose the Disabled functionality inadvertently..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

init_resource doesn't overwrite existing resources. You'd have to explicitly call .insert_resource(DefaultQueryFilters::default()) which is probably verbose enough to make it obvious what will happen. Currently it is intended that you can opt-out of entity disabling, but as the feature matures we could consider making it so that it is always there.


/// A marker component for disabled entities. See [the module docs] for more info.
///
/// [the module docs]: crate::entity_disabling
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we update the module docs to mention that the Disabled component is disabled in the default DefaultQueryFilters? Right now they talk about it as a hypothetical.

let original_world_dqf_id = self
.original_world
.components()
.get_resource_id(TypeId::of::<DefaultQueryFilters>());
Copy link
Contributor

Choose a reason for hiding this comment

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

It will be nice when resources-as-components lets us use default query filters to exclude the default query filters resource from our resource query :).

@MrGVSV MrGVSV added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 30, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Feb 2, 2025
Merged via the queue into bevyengine:main with commit 62285a4 Feb 2, 2025
29 checks passed
mrchantey pushed a commit to mrchantey/bevy that referenced this pull request Feb 4, 2025
# Objective

We have default query filters now, but there is no first-party marker
for entity disabling yet
Fixes bevyengine#17458

## Solution

Add the marker, cool recursive features and/or potential hook changes
should be follow up work

## Testing

Added a unit test to check that the new marker is enabled by default
joshua-holmes pushed a commit to joshua-holmes/bevy that referenced this pull request Feb 5, 2025
# Objective

We have default query filters now, but there is no first-party marker
for entity disabling yet
Fixes bevyengine#17458

## Solution

Add the marker, cool recursive features and/or potential hook changes
should be follow up work

## Testing

Added a unit test to check that the new marker is enabled by default
github-merge-queue bot pushed a commit that referenced this pull request Feb 9, 2025
# Objective

The entity disabling / default query filter work added in #17514 and
#13120 is neat, but we don't teach users how it works!

We should fix that before 0.16.

## Solution

Write a simple example to teach the basics of entity disabling!

## Testing

`cargo run --example entity_disabling`

## Showcase


![image](https://github.com/user-attachments/assets/9edcc5e1-2bdf-40c5-89b7-5b61c817977a)

---------

Co-authored-by: Zachary Harrold <[email protected]>
github-merge-queue bot pushed a commit that referenced this pull request Feb 11, 2025
…y filters (#17768)

# Objective

Currently, default query filters, as added in #13120 / #17514 are
hardcoded to only use a single query filter.

This is limiting, as multiple distinct disabling components can serve
important distinct roles. I ran into this limitation when experimenting
with a workflow for prefabs, which don't represent the same state as "an
entity which is temporarily nonfunctional".

## Solution

1. Change `DefaultQueryFilters` to store a SmallVec of ComponentId,
rather than an Option.
2. Expose methods on `DefaultQueryFilters`, `World` and `App` to
actually configure this.
3. While we're here, improve the docs, write some tests, make use of
FromWorld and make some method names more descriptive.

## Follow-up

I'm not convinced that supporting sparse set disabling components is
useful, given the hit to iteration performance and runtime checks
incurred. That's disjoint from this PR though, so I'm not doing it here.
The existing warnings are fine for now.

## Testing

I've added both a doc test and an mid-level unit test to verify that
this works!
mrchantey pushed a commit to mrchantey/bevy that referenced this pull request Feb 17, 2025
# Objective

The entity disabling / default query filter work added in bevyengine#17514 and
bevyengine#13120 is neat, but we don't teach users how it works!

We should fix that before 0.16.

## Solution

Write a simple example to teach the basics of entity disabling!

## Testing

`cargo run --example entity_disabling`

## Showcase


![image](https://github.com/user-attachments/assets/9edcc5e1-2bdf-40c5-89b7-5b61c817977a)

---------

Co-authored-by: Zachary Harrold <[email protected]>
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-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes 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.

Add a first-party Disabled component
6 participants