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

[Merged by Bors] - Add warning when a hierarchy component is missing #5590

Conversation

nicopap
Copy link
Contributor

@nicopap nicopap commented Aug 6, 2022

Objective

A common pitfall since 0.8 is the requirement on ComputedVisibility
being present on all ancestors of an entity that itself has
ComputedVisibility, without which, the entity becomes invisible.

I myself hit the issue and got very confused, and saw a few people hit
it as well, so it makes sense to provide a hint of what to do when such
a situation is encountered.

Solution

We now check that all entities with both a Parent and a
ComputedVisibility component have parents that themselves have a
ComputedVisibility component.

Note that the warning is only printed once.

We also add a similar warning to GlobalTransform.

This only emits a warning. Because sometimes it could be an intended
behavior.

Alternatives:


Changelog

  • Add a warning when encountering dubious component hierarchy structure

@nicopap nicopap added C-Docs An addition or correction to our documentation C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Diagnostics Logging, crash handling, error reporting and performance analysis A-Hierarchy Parent-child entity hierarchies labels Aug 6, 2022
@nicopap nicopap force-pushed the warn-against-missing-computed-visibility branch from a95bc6a to b021e81 Compare August 6, 2022 09:08
@nicopap nicopap requested a review from mockersf August 6, 2022 09:12
@@ -20,6 +23,29 @@ pub struct DespawnChildrenRecursive {
pub entity: Entity,
}

/// System to print a warning if at any time we detect an inconsistent hierarchy.
pub fn hierarchy_healthcheck_system<T: Component>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I defined it in the bevy_hierarchy crate to reflect #5507

@ramirezmike
Copy link
Contributor

I like this change but did have one comment about the term "HealthCheck" although please take it with a grain of salt; I'm pretty new at looking at Bevy code!

To me it's not quite clear from "hierarchy_healthcheck_system" or the VisibilitySystems enum variant "HealthCheck" that it's related to verifying that the entities within a hierarchy are consistent with regards to these specific (hierarchy-affecting?) components. My initial reaction is "what is a healthy hierarchy vs unhealthy?"

hierarchy_consistency_check_system and VisibilitySystems::CheckHierarchyConsistency or something like that? Again, it's totally possible HealthCheck is an established pattern that I'm oblivious to though just thought I'd comment and learn

@nicopap
Copy link
Contributor Author

nicopap commented Aug 8, 2022

@ramirezmike I actually took the "health check" term from both neovim and my previous job (where we created a tool to check if internal services were online).

I do agree that what the system does is not well reflected in the helthcheck name,
but I don't think that hierarchy_consistency_check is necessarily clearer than hierarchy_healthcheck. Neither of those hint at what it actually being checked, which is that no parents are missing the required component.

Maybe there is a better name yeT?

@ramirezmike
Copy link
Contributor

I do agree that what the system does is not well reflected in the helthcheck name, but I don't think that hierarchy_consistency_check is necessarily clearer than hierarchy_healthcheck. Neither of those hint at what it actually being checked, which is that no parents are missing the required component.

Maybe there is a better name yeT?

Perhaps we will discover it!

hierarchy_component_mismatch_check?

@nicopap nicopap marked this pull request as draft August 10, 2022 16:23
@nicopap nicopap force-pushed the warn-against-missing-computed-visibility branch from b021e81 to 26b8f08 Compare August 18, 2022 09:38
@nicopap nicopap marked this pull request as ready for review August 18, 2022 10:04
@nicopap nicopap requested review from cart, ramirezmike and killercup and removed request for ramirezmike and killercup August 18, 2022 10:04
@mockersf
Copy link
Member

This feels like the same kind of diagnostic level as system ordering ambiguities, and with the same kind of consequences in case of an issue (it kinda doesn't work but not in an explicit way).

What do you think of having a resource ReportHierarchyIssue similar to ReportExecutionOrderAmbiguities, and add those systems if the resource is present?

@nicopap
Copy link
Contributor Author

nicopap commented Aug 19, 2022

What do you think of having a resource ReportHierarchyIssue similar to ReportExecutionOrderAmbiguities, and add those systems if the resource is present?

I like the idea, but I think it should be on by default. Supposedly, the user only benefits from the warning message if they don't know why their code is not working. But adding the resource requires knowing why their code is not working, making the message moot. The resource could be added on #[cfg(debug_assertions)] though, which I think is still better than adding the plugin on cfg flag.

@nicopap nicopap force-pushed the warn-against-missing-computed-visibility branch from 69184e8 to 6e46fa9 Compare September 1, 2022 07:28
crates/bevy_hierarchy/src/valid_parent_check_plugin.rs Outdated Show resolved Hide resolved
errors/B0004.md Outdated Show resolved Hide resolved
errors/B0004.md Outdated Show resolved Hide resolved
errors/B0004.md Outdated Show resolved Hide resolved
@nicopap nicopap force-pushed the warn-against-missing-computed-visibility branch from 6e46fa9 to e5db0f9 Compare September 5, 2022 11:25
Copy link
Contributor

@tim-blackbird tim-blackbird left a comment

Choose a reason for hiding this comment

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

Looking good. Just a couple nits.

errors/B0004.md Outdated Show resolved Hide resolved
@nicopap
Copy link
Contributor Author

nicopap commented Sep 12, 2022

Btw I counted three more questions that would have been answered by this diagnostic.

@nicopap nicopap force-pushed the warn-against-missing-computed-visibility branch from c1bbab5 to 4617dbf Compare September 12, 2022 13:55
nicopap and others added 5 commits September 12, 2022 15:55
A common pitfall since 0.8 is the requirement on `ComputedVisibility`
being present on all ancestors of an entity that itself has
`ComputedVisibility`, without which, the entity becomes invisible.

I myself hit the issue and got very confused, and saw a few people hit
it as well, so it makes sense to provide a hint of what to do when such
a situation is encountered.

We now check that all entities with both a `Parent` and a
`ComputedVisibility` component have parents that themselves have a
`ComputedVisibility` component.

Note that the warning is only printed once.

We also add a similar warning to `GlobalTransform`.

This only emits a warning. Because sometimes it could be an intended
behavior.

Alternatives:
- Do nothing and keep repeating to newcomers how to avoid recurring
  pitfalls
- Make the transform and visibility propagations tolerant to missing
  components
Co-authored-by: ira <JustTheCoolDude@gmail.com>
Co-authored-by: ira <JustTheCoolDude@gmail.com>
@nicopap nicopap force-pushed the warn-against-missing-computed-visibility branch from 4617dbf to 61a0c75 Compare September 12, 2022 13:55
@IceSentry IceSentry 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 Sep 12, 2022
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

Annoying that we need this, but this is a very well-crafted diagnostic.

bors r+

bors bot pushed a commit that referenced this pull request Sep 19, 2022
# Objective

A common pitfall since 0.8 is the requirement on `ComputedVisibility`
being present on all ancestors of an entity that itself has
`ComputedVisibility`, without which, the entity becomes invisible.

I myself hit the issue and got very confused, and saw a few people hit
it as well, so it makes sense to provide a hint of what to do when such
a situation is encountered.

- Fixes #5849
- Closes #5616
- Closes #2277 
- Closes #5081

## Solution

We now check that all entities with both a `Parent` and a
`ComputedVisibility` component have parents that themselves have a
`ComputedVisibility` component.

Note that the warning is only printed once.

We also add a similar warning to `GlobalTransform`.

This only emits a warning. Because sometimes it could be an intended
behavior.

Alternatives:
- Do nothing and keep repeating to newcomers how to avoid recurring
  pitfalls
- Make the transform and visibility propagation tolerant to missing
  components (#5616)
- Probably archetype invariants, though the current draft would not
  allow detecting that kind of errors

---

## Changelog

- Add a warning when encountering dubious component hierarchy structure


Co-authored-by: Nicola Papale <nicopap@users.noreply.github.com>
@bors
Copy link
Contributor

bors bot commented Sep 19, 2022

Build failed (retrying...):

bors bot pushed a commit that referenced this pull request Sep 19, 2022
# Objective

A common pitfall since 0.8 is the requirement on `ComputedVisibility`
being present on all ancestors of an entity that itself has
`ComputedVisibility`, without which, the entity becomes invisible.

I myself hit the issue and got very confused, and saw a few people hit
it as well, so it makes sense to provide a hint of what to do when such
a situation is encountered.

- Fixes #5849
- Closes #5616
- Closes #2277 
- Closes #5081

## Solution

We now check that all entities with both a `Parent` and a
`ComputedVisibility` component have parents that themselves have a
`ComputedVisibility` component.

Note that the warning is only printed once.

We also add a similar warning to `GlobalTransform`.

This only emits a warning. Because sometimes it could be an intended
behavior.

Alternatives:
- Do nothing and keep repeating to newcomers how to avoid recurring
  pitfalls
- Make the transform and visibility propagation tolerant to missing
  components (#5616)
- Probably archetype invariants, though the current draft would not
  allow detecting that kind of errors

---

## Changelog

- Add a warning when encountering dubious component hierarchy structure


Co-authored-by: Nicola Papale <nicopap@users.noreply.github.com>
@bors bors bot changed the title Add warning when a hierarchy component is missing [Merged by Bors] - Add warning when a hierarchy component is missing Sep 19, 2022
@bors bors bot closed this Sep 19, 2022
james7132 pushed a commit to james7132/bevy that referenced this pull request Oct 19, 2022
# Objective

A common pitfall since 0.8 is the requirement on `ComputedVisibility`
being present on all ancestors of an entity that itself has
`ComputedVisibility`, without which, the entity becomes invisible.

I myself hit the issue and got very confused, and saw a few people hit
it as well, so it makes sense to provide a hint of what to do when such
a situation is encountered.

- Fixes bevyengine#5849
- Closes bevyengine#5616
- Closes bevyengine#2277 
- Closes bevyengine#5081

## Solution

We now check that all entities with both a `Parent` and a
`ComputedVisibility` component have parents that themselves have a
`ComputedVisibility` component.

Note that the warning is only printed once.

We also add a similar warning to `GlobalTransform`.

This only emits a warning. Because sometimes it could be an intended
behavior.

Alternatives:
- Do nothing and keep repeating to newcomers how to avoid recurring
  pitfalls
- Make the transform and visibility propagation tolerant to missing
  components (bevyengine#5616)
- Probably archetype invariants, though the current draft would not
  allow detecting that kind of errors

---

## Changelog

- Add a warning when encountering dubious component hierarchy structure


Co-authored-by: Nicola Papale <nicopap@users.noreply.github.com>
james7132 pushed a commit to james7132/bevy that referenced this pull request Oct 28, 2022
# Objective

A common pitfall since 0.8 is the requirement on `ComputedVisibility`
being present on all ancestors of an entity that itself has
`ComputedVisibility`, without which, the entity becomes invisible.

I myself hit the issue and got very confused, and saw a few people hit
it as well, so it makes sense to provide a hint of what to do when such
a situation is encountered.

- Fixes bevyengine#5849
- Closes bevyengine#5616
- Closes bevyengine#2277 
- Closes bevyengine#5081

## Solution

We now check that all entities with both a `Parent` and a
`ComputedVisibility` component have parents that themselves have a
`ComputedVisibility` component.

Note that the warning is only printed once.

We also add a similar warning to `GlobalTransform`.

This only emits a warning. Because sometimes it could be an intended
behavior.

Alternatives:
- Do nothing and keep repeating to newcomers how to avoid recurring
  pitfalls
- Make the transform and visibility propagation tolerant to missing
  components (bevyengine#5616)
- Probably archetype invariants, though the current draft would not
  allow detecting that kind of errors

---

## Changelog

- Add a warning when encountering dubious component hierarchy structure


Co-authored-by: Nicola Papale <nicopap@users.noreply.github.com>
@nicopap nicopap mentioned this pull request Jan 19, 2023
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
# Objective

A common pitfall since 0.8 is the requirement on `ComputedVisibility`
being present on all ancestors of an entity that itself has
`ComputedVisibility`, without which, the entity becomes invisible.

I myself hit the issue and got very confused, and saw a few people hit
it as well, so it makes sense to provide a hint of what to do when such
a situation is encountered.

- Fixes bevyengine#5849
- Closes bevyengine#5616
- Closes bevyengine#2277 
- Closes bevyengine#5081

## Solution

We now check that all entities with both a `Parent` and a
`ComputedVisibility` component have parents that themselves have a
`ComputedVisibility` component.

Note that the warning is only printed once.

We also add a similar warning to `GlobalTransform`.

This only emits a warning. Because sometimes it could be an intended
behavior.

Alternatives:
- Do nothing and keep repeating to newcomers how to avoid recurring
  pitfalls
- Make the transform and visibility propagation tolerant to missing
  components (bevyengine#5616)
- Probably archetype invariants, though the current draft would not
  allow detecting that kind of errors

---

## Changelog

- Add a warning when encountering dubious component hierarchy structure


Co-authored-by: Nicola Papale <nicopap@users.noreply.github.com>
@nicopap nicopap deleted the warn-against-missing-computed-visibility branch September 5, 2023 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Diagnostics Logging, crash handling, error reporting and performance analysis A-Hierarchy Parent-child entity hierarchies C-Docs An addition or correction to our documentation C-Usability A targeted quality-of-life change that makes Bevy easier to use 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
8 participants