Skip to content

Attaching an AmbientLight to a Camera causes unexpected warning message #19203

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

Open
phi-fell opened this issue May 13, 2025 · 4 comments
Open
Labels
C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled

Comments

@phi-fell
Copy link

Bevy version

Bevy "0.16" via cargo

[Optional] Relevant system information

cargo 1.86.0

Windows 11 Home 64 bit

AdapterInfo { name: "NVIDIA GeForce RTX 4070 SUPER", vendor: 4318, device: 10115, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "572.70", backend: Vulkan }

What you did

Attached an AmbientLight component to an entity with a camera:

Cargo.toml

[package]
name = "ambient_light_issue"
version = "0.1.0"
edition = "2024"

[dependencies]
bevy = "0.16.0"

src/main.rs

use bevy::prelude::*;

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

fn setup_camera(mut commands: Commands) {
    commands.spawn((Camera2d, Camera { ..default() }, AmbientLight::NONE));
}

(also works without the explicit Camera component, or with a Camera3d, etc.)

What went wrong

Warning:
WARN bevy_render::camera::camera: Entity 3v1 has a Camera component, but it doesn't have a render graph configured. Consider adding a Camera2d or Camera3d component, or manually adding a CameraRenderGraph component if you need a custom render graph.

Additional information

Removing the AmbientLight component fixes it. printing a list of entities with Camera components during Update, does not print 3v1, and 3v1 is not the id of the spawned entity with the light and camera

@phi-fell phi-fell added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels May 13, 2025
@christopherverch
Copy link

I'm not super famiilar with how bevy 0.16 actually spawns things with required components, but from some testing it appears 3v1 is the "temporary" entity while it's still being set up. AmbientLight has #[require(Camera)], and it seems this is being added before the Camera3d's required components (which includes the rendergraph). I think it's because on_add is being run as soon as the Camera component is added, so the check runs before the Camera3d components are added.

Strangely I get the error twice just by spawning the ambient light by itself, maybe because of the same temporary entity? Removing the require(Camera) from AmbientLight removes the warning, so it seems like this is an issue with ambientlight's required components being added before Camera3d. Seems like checks like these shouldn't run until the entire entity is finished loading?

@phi-fell
Copy link
Author

In case this is useful: the entity it prints isn't consistent in a larger project. Here's (a small selection of) the actual output spam I'm getting where I encountered this

Output
2025-05-15T04:30:47.655890Z  WARN bevy_render::camera::camera: Entity 207v100 has a `Camera` component, but it doesn't have a render graph configured. Consider adding a `Camera2d` or `Camera3d` component, or manually adding a `CameraRenderGraph` component if you need a custom render graph.
2025-05-15T04:30:47.656021Z  WARN bevy_render::camera::camera: Entity 227v36 has a `Camera` component, but it doesn't have a render graph configured. Consider adding a `Camera2d` or `Camera3d` component, or manually adding a `CameraRenderGraph` component if you need a custom render graph.
2025-05-15T04:30:47.656091Z  WARN bevy_render::camera::camera: Entity 265v334 has a `Camera` component, but it doesn't have a render graph configured. Consider adding a `Camera2d` or `Camera3d` component, or manually adding a `CameraRenderGraph` component if you need a custom render graph.
2025-05-15T04:30:47.656165Z  WARN bevy_render::camera::camera: Entity 268v334 has a `Camera` component, but it doesn't have a render graph configured. Consider adding a `Camera2d` or `Camera3d` component, or manually adding a `CameraRenderGraph` component if you need a custom render graph.
2025-05-15T04:30:47.656329Z  WARN bevy_render::camera::camera: Entity 271v196 has a `Camera` component, but it doesn't have a render graph configured. Consider adding a `Camera2d` or `Camera3d` component, or manually adding a `CameraRenderGraph` component if you need a custom render graph.
2025-05-15T04:30:47.656448Z  WARN bevy_render::camera::camera: Entity 508v2 has a `Camera` component, but it doesn't have a render graph configured. Consider adding a `Camera2d` or `Camera3d` component, or manually adding a `CameraRenderGraph` component if you need a custom render graph.
2025-05-15T04:30:47.656545Z  WARN bevy_render::camera::camera: Entity 505v2 has a `Camera` component, but it doesn't have a render graph configured. Consider adding a `Camera2d` or `Camera3d` component, or manually adding a `CameraRenderGraph` component if you need a custom render graph.
2025-05-15T04:30:47.656639Z  WARN bevy_render::camera::camera: Entity 472v2 has a `Camera` component, but it doesn't have a render graph configured. Consider adding a `Camera2d` or `Camera3d` component, or manually adding a `CameraRenderGraph` component if you need a custom render graph.
2025-05-15T04:30:47.656732Z  WARN bevy_render::camera::camera: Entity 469v2 has a `Camera` component, but it doesn't have a render graph configured. Consider adding a `Camera2d` or `Camera3d` component, or manually adding a `CameraRenderGraph` component if you need a custom render graph.
2025-05-15T04:30:47.656814Z  WARN bevy_render::camera::camera: Entity 502v2 has a `Camera` component, but it doesn't have a render graph configured. Consider adding a `Camera2d` or `Camera3d` component, or manually adding a `CameraRenderGraph` component if you need a custom render graph.
2025-05-15T04:30:47.656887Z  WARN bevy_render::camera::camera: Entity 499v2 has a `Camera` component, but it doesn't have a render graph configured. Consider adding a `Camera2d` or `Camera3d` component, or manually adding a `CameraRenderGraph` component if you need a custom render graph.
2025-05-15T04:30:47.656960Z  WARN bevy_render::camera::camera: Entity 466v2 has a `Camera` component, but it doesn't have a render graph configured. Consider adding a `Camera2d` or `Camera3d` component, or manually adding a `CameraRenderGraph` component if you need a custom render graph.
2025-05-15T04:30:47.657045Z  WARN bevy_render::camera::camera: Entity 463v2 has a `Camera` component, but it doesn't have a render graph configured. Consider adding a `Camera2d` or `Camera3d` component, or manually adding a `CameraRenderGraph` component if you need a custom render graph.
2025-05-15T04:30:47.657113Z  WARN bevy_render::camera::camera: Entity 496v2 has a `Camera` component, but it doesn't have a render graph configured. Consider adding a `Camera2d` or `Camera3d` component, or manually adding a `CameraRenderGraph` component if you need a custom render graph.
2025-05-15T04:30:47.657190Z  WARN bevy_render::camera::camera: Entity 493v2 has a `Camera` component, but it doesn't have a render graph configured. Consider adding a `Camera2d` or `Camera3d` component, or manually adding a `CameraRenderGraph` component if you need a custom render graph.

I also tested adding the ambient light later, and inserting it after the fact, even in Update doesn't remove the error, but if I wait a full frame and then insert it, the warning doesn't occur.

i.e.

use bevy::{diagnostic::FrameCount, prelude::*};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup_camera)
        .add_systems(
            Update,
            |mut commands: Commands,
             frames: Res<FrameCount>,
             camera: Single<Entity, With<Camera2d>>| {

                if frames.0 == 0 {
                    let c = camera.into_inner();
                    println!("Ambient Light added to Camera: {c}");
                    commands.entity(c).insert(AmbientLight::NONE);
                }
            },
        )
        .run();
}

fn setup_camera(mut commands: Commands) {
    let id = commands.spawn(Camera2d).id();
    println!("Initial Camera: {id}")
}

outputs

Initial Camera: 7v1
Ambient Light added to Camera: 7v1
2025-05-15T04:43:02.181516Z  WARN bevy_render::camera::camera: Entity 3v1 has a `Camera` component, but it doesn't have a render graph configured. Consider adding a `Camera2d` or `Camera3d` component, or manually adding a `CameraRenderGraph` component if you need a custom render graph.

but

use bevy::{diagnostic::FrameCount, prelude::*};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup_camera)
        .add_systems(
            Update,
            |mut commands: Commands,
             frames: Res<FrameCount>,
             camera: Single<Entity, With<Camera2d>>| {
                // wait a full frame
                if frames.0 == 1 {
                    let c = camera.into_inner();
                    println!("Ambient Light added to Camera: {c}");
                    commands.entity(c).insert(AmbientLight::NONE);
                }
            },
        )
        .run();
}

fn setup_camera(mut commands: Commands) {
    let id = commands.spawn(Camera2d).id();
    println!("Initial Camera: {id}")
}

outputs

Initial Camera: 7v1
Ambient Light added to Camera: 7v1

What's most odd to me is that I can't seem to trigger this with any other required component. Presumably there's something special or hardcoded with AmbientLight in particular?

@christopherverch
Copy link

christopherverch commented May 16, 2025

it's because ambientlight has Camera as a requiredcomponent (Camera, not Camera2d/3d), and Camera has #[component(on_add = warn_on_no_render_graph)], aka check for the rendergraph when Camera component is added. Basically the Camera component is being added due to AmbientLight, and the Camera2d's requiredcomponents aren't set up yet. Doing some testing, the Camera2d is also added to that same entity (3v1) but it looks like the AmbientLight's requiredcomponents are added first, then the camera2d's.

Turns out it's not a temporary entity, bevy's renderer keeps a separate "renderentity" in a separate ecs world. You can see that with

fn print_camera(cam_q: Query<(Entity, RenderEntity), With<Camera2d>>) {
    println!("camera entity: {:?}", cam_q.iter().next());
}

this prints out the Entity (main world) and the RenderEntity(render world)

If "Camera" is removed as a required component of Camera2d, delaying the ambientlight add by 1 frame no longer resolves the warning, so the issue is AmbientLight adding a Camera component. Adding a check for CameraRenderGraph in on_added on Camera2d succeeds the CameraRenderGraph check, so I'm 90% sure this is an ordering issue, though it's weird this check would happen in between adding the requiredcomponents of each.

@phi-fell
Copy link
Author

It makes sense that the entity id is for one in the render world. That also explains why changing which components I add, or in which order, has no effect unless it's in the next frame (i.e. after a run of the extraction phase).

My reason for mentioning Camera2d and Camera3d is that they also #[require(Camera)] but do not trigger the warning.

So if I understand correctly, the issue is that AmbientLight is extracted and added to the render world entity before the CameraRenderGraph, and then the require and on_add hooks are run immediately, before other components are extracted?

Whereas Camera, and Camera2d/Camera3d (which both require(Camera) and would therefore insert it) all end up extracted after CameraRenderGraph (and so don't trigger a warning)

I notice that Camera2d and Camera3d both have #[extract_component_filter(With<Camera>)] - could this be having an effect on the ordering?

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-Needs-Triage This issue needs to be labelled
Projects
None yet
Development

No branches or pull requests

2 participants