-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Comments
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? |
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
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.
outputs
but
outputs
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? |
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
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. |
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 So if I understand correctly, the issue is that Whereas I notice that Camera2d and Camera3d both have |
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
src/main.rs
(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 aCamera2d
orCamera3d
component, or manually adding aCameraRenderGraph
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 cameraThe text was updated successfully, but these errors were encountered: