bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
35.36k stars 3.49k forks source link

non-root `TargetCamera`s are not ignored #15143

Open ickshonpe opened 2 weeks ago

ickshonpe commented 2 weeks ago

Bevy version

main

What you did

Added this system to render_ui_to_texture:

fn target_cameras(
    mut commands: Commands,
    mut count: Local<usize>,
    mut query: Query<&mut TargetCamera, With<Parent>>,
) {
    *count += 1;
    if *count == 2 {
        // spawn a UI camera!
        let ui_camera = commands
            .spawn(Camera2dBundle {
                camera: Camera {
                    order: 10,
                    ..Default::default()
                },
                ..Default::default()
            })
            .id();

        for mut c in query.iter_mut() {
            c.0 = ui_camera;
        }
    }
}

What went wrong

rtt

Non-root TargetCameras are meant to have no effect but update_target_camera_system only does an update if it detects changes to the root node's TargetCamera and not the TargetCamera components of any of the rest of the entities in the UI node tree.

ickshonpe commented 2 weeks ago

I think the fix is to probably to not update the target cameras components at all, and instead have a resolved_camera_entity field in Node or something.