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

Entities are invisible when spawned as child via add_child() #6105

Closed
svenallers opened this issue Sep 26, 2022 · 4 comments
Closed

Entities are invisible when spawned as child via add_child() #6105

svenallers opened this issue Sep 26, 2022 · 4 comments
Labels
C-Bug An unexpected or incorrect behavior S-Duplicate This issue or PR already exists

Comments

@svenallers
Copy link

Bevy version

0.8.1 (I also tested on master branch (39467e3) and did have the sam issue)

[Optional] Relevant system information

Rust version: 1.64.0
OS: Windows 11 & Mac OS Monterey 12.6

AdapterInfo { name: "AMD Radeon Pro 5300M", vendor: 0, device: 0, device_type: DiscreteGpu, backend: Metal }

I tested it on an Nvidia RTX 3070ti with Vulkan as the backend as well and did have the same issue.

What you did

I tried to spawn an entity as a child of another entity but it was not visible. After downgrading to 0.7.0 everything went fine. Thus I assume that this is a regression introduced with 0.8.

The code to reproduce:

use bevy::prelude::*;

const RECT_SIZE: f32 = 16.0;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_startup_system(spawn_camera)
        .add_startup_system(spawn_as_child)
        .run();
}

fn spawn_camera(mut commands: Commands) {
    commands.spawn_bundle(Camera2dBundle::default()); // use OrthographicCameraBundle::new_2d() in 0.7.0
}

fn spawn_as_child(mut commands: Commands) {
    let rect_entity = commands
        .spawn_bundle(SpriteBundle {
            sprite: Sprite {
                color: Color::RED,
                custom_size: Some(Vec2::splat(RECT_SIZE)),
                ..Default::default()
            },
            ..Default::default()
        })
        .insert(Transform::default())
        .id();

    commands
        .spawn()
        .insert_bundle(TransformBundle::default())
        .add_child(rect_entity);
}

What went wrong

The sprite spawned is not visible in 0.8.1:
0 8 1

I expected to see a red rectangle as you do in version 0.7.0:
0 7 0

@svenallers svenallers added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Sep 26, 2022
@DJMcNab
Copy link
Member

DJMcNab commented Sep 26, 2022

I think the parent needs to have a Visibility component

@nicopap
Copy link
Contributor

nicopap commented Sep 26, 2022

Should be fixed by #5590
To fix this, do this:

// replace this line when spawning the parent entity
         .insert_bundle(TransformBundle::default())
// by the following line
         .insert_bundle(SpatialBundle::default())

@nicopap nicopap added S-Duplicate This issue or PR already exists A-Hierarchy and removed S-Needs-Triage This issue needs to be labelled labels Sep 26, 2022
@svenallers
Copy link
Author

Thanks, you saved my day 🙂 Using SpatialBundle worked. This issue was driving me nuts yesterday. I did try using the Visibility component before already but it did not work. I did not know about the ComputedVisibility component.

@nicopap
Copy link
Contributor

nicopap commented Sep 26, 2022

This issue was driving me nuts yesterday.

Don't worry, you are not the only one. I've counted a dozen people that got very frustrated by that. (including me, twice) I'm glad the warning message will make it to 0.9.0

@nicopap nicopap closed this as completed Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Bug An unexpected or incorrect behavior S-Duplicate This issue or PR already exists
Projects
None yet
Development

No branches or pull requests

3 participants