Skip to content

Conversation

@andriyDev
Copy link
Contributor

@andriyDev andriyDev commented Jan 24, 2026

Objective

Solution

Instead of warning in the hook, we instead send a message for the entity if its parent is missing the component. A system later reads these messages and checks again if the parent is missing the component, and only then logs. This is done by:

  • Change the hook into an observer.
  • Create a message to indicate a check is needed.
  • Create a system to do this check.
  • Create a plugin in bevy_app to add all these things to the app.
    • I couldn't think of a better place to put this, other than like bevy_util, but I didn't want to add to the "kitchen sink".
  • Switch GlobalTransform/InheritedVisibility to use this plugin instead.
    • One thing to note is I only perform this check in the Last schedule. We could move this check if necessary, but I doubt many users will spawn a child, and then only add the parent's GlobalTransform after PostUpdate (not sure if this will even affect transform propagation though?)

Note: the memory usage is proportional to how many of these bad entities you spawn in a single frame.

Testing

  • I ran the following example:
use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .run();
}

fn setup(mut commands: Commands) {
    let parent = commands.spawn_empty().id();
    let child = commands.spawn_empty().id();

    // Initialize the child first, add the Visibility+Transform component, which implicitly adds the
    // InheritedVisibility+GlobalTransform component as well.
    commands
        .entity(child)
        .insert((ChildOf(parent), Visibility::Inherited, Transform::default()));

    // Also make the parent add the Visibility+Transform component so it is valid.
    commands
        .entity(parent)
        .insert((Visibility::Inherited, Transform::default()));
}

On main, this logs two warnings. With this PR, there are no logs! I also verified that omitting attaching the components to the parent still logs the warning.

@andriyDev andriyDev added C-Bug An unexpected or incorrect behavior A-ECS Entities, components, systems, and events D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 24, 2026
@andriyDev andriyDev added this to the 0.19 milestone Jan 24, 2026
@ChristopherBiscardi
Copy link
Contributor

oooh nicely done. I'm a bit tired tonight so I'll give it an actual review tomorrow, but on scanning the approach looks good to me, and I like that it only uses resources for the "bad cases", which feels aligned with the original implementation.

Copy link
Contributor

@ChristopherBiscardi ChristopherBiscardi left a comment

Choose a reason for hiding this comment

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

One thing to note is I only perform this check in the Last schedule. We could move this check if necessary, but I doubt many users will spawn a child, and then only add the parent's GlobalTransform after PostUpdate (not sure if this will even affect transform propagation though?)

Since GlobalTransform is a required component of Transform I don't think there's a way for this to cause issues unless bevy support is disabled for transform.

iirc this was the issue that boiled down to being an archetype ordering issue in the scene spawning logic, so it would be hard to write a real test for it, but the previous approach was inherently flawed in that way.

I've run some examples locally and was able to use the new plugin to trigger the log on AnimationPlayer in the animated_mesh example (which obviously should not have another player on the parent).

Copy link
Contributor

@kfc35 kfc35 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 to me! Appreciate the thorough documentation

I checked out the branch and ran the test example in the PR; everything looks good and I also get no warnings in the branch versus the two on main about InheritedVisibility and GlobalTransform

@kfc35 kfc35 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 25, 2026
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-Bug An unexpected or incorrect behavior 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warning B0004 (“InheritedVisibility”) when loading a glTF exported from Blender with shape keys B0004 check sometimes triggers false positives

3 participants