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

Add entity disabling example #17710

Merged

Conversation

alice-i-cecile
Copy link
Member

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

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Examples An addition or correction to our examples X-Uncontroversial This work is generally agreed upon D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Feb 6, 2025
@alice-i-cecile alice-i-cecile added this to the 0.16 milestone Feb 6, 2025
Copy link
Contributor

github-actions bot commented Feb 6, 2025

The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.

Copy link
Contributor

@bushrat011899 bushrat011899 left a comment

Choose a reason for hiding this comment

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

Looks good! I love an interactive example, especially small ones like this. I have an alternate method for avoiding disabling the window and text entities suggested, and some minor documentation items.

Comment on lines 45 to 48
// Just add the `Disabled` component to the entity to disable it.
// Note that the `Disabled` component is *only* added to the entity,
// its children are not affected.
commands.entity(clicked_entity).insert(Disabled);
Copy link
Contributor

Choose a reason for hiding this comment

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

That's interesting! Since the entity is disabled, does that cause the parent/child relationship to break, orphaning those children? Or does the relationship stick around and the children just have a disabled parent?

Copy link
Member Author

Choose a reason for hiding this comment

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

The latter :) I don't think much of our code is robust to it yet though!


fn disable_entities_on_click(
trigger: Trigger<Pointer<Click>>,
ignored_query: Query<(), Or<(With<Window>, With<Text>)>>,
Copy link
Contributor

@Carter0 Carter0 Feb 7, 2025

Choose a reason for hiding this comment

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

This query is super fascinating to me cause you are querying for 'Void' with some stuff on it. I know that's not the point of this example, but what's the difference between this and just querying for all entities with those components and then doing an equality check on the entities below?

Copy link
Member Author

Choose a reason for hiding this comment

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

This will avoid actually fetching / locking the data :) We don't actually care about the data contained inside!

Copy link
Contributor

@Carter0 Carter0 left a comment

Choose a reason for hiding this comment

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

I ran this example and it works well! Only real feedback is on the visibility comment above, but I don't really think it matters all that much.

@alice-i-cecile alice-i-cecile removed the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Feb 9, 2025
@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 Feb 9, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Feb 9, 2025
Merged via the queue into bevyengine:main with commit 33e8333 Feb 9, 2025
32 checks passed
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-Examples An addition or correction to our examples D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Uncontroversial This work is generally agreed upon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants