bevyengine / bevyengine/bevy

Parent components require Transform in addition to GlobalTransform, but there's no warning about it

Open
#10,600 0 comments 0 reactions 0 assignees View on GitHub
A-Diagnostics A-Transform C-Bug
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version

0.12.0

## What you did

```rust
use bevy::app::App;
use bevy::app::Startup;
use bevy::prelude::*;

fn setup(
mut commands: Commands,
mut materials: ResMut>,
mut meshes: ResMut>,
) {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(3.0, 3.0, 3.0).looking_at(Vec3::new(0., 0., 0.), Vec3::Y),
..default()
});

// Control cube at 0,0,0
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.1 })),
material: materials.add(Color::BLUE.into()),
..Default::default()
});

// Cube at 1,0,0
commands.spawn((
GlobalTransform::default(),
// Comment this out, and transform below won't work.
Transform::default(),
InheritedVisibility::default(),
)).with_children(|commands| {
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.5 })),
material: materials.add(Color::RED.into()),
transform: Transform::from_xyz(1., 0., 0.),
..Default::default()
});
});
}

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

## What went wrong

Comment out `Transform::default()` at parent component, and child transform won't work.

There's warning on the console about missing `GlobalTransform`, but there's no warning about missing `Transform`. So I don't know where the problem is, in implementation, or in diagnostics.

Warning about missing `GlobalTransform` looks liks this:

```
2023-11-17T00:06:37.863170Z WARN bevy_hierarchy::valid_parent_check_plugin: warning[B0004]: An entity with the GlobalTransform component has a parent without GlobalTransform.
```

Also I suspect the warning about may also include recommendation to use `SpatialBundle`, but I don't understand it well enough.

## Additional information

Correct rendering of the program above:

image

Comment out `Transform::default()` in the parent component, and it is rendered ignoring child transform:

image

Contributor guide

Open the contributing guide

Research direction

Reproduce the example from the setup system in the issue and compare the existing warning from bevy_hierarchy::valid_parent_check_plugin. Trace how the parent and child transform components are handled; done means the missing-Transform case produces a useful diagnostic and the reported example behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.