From 2aaaed7f69d3a8ff001e1392904394b2bea8333b Mon Sep 17 00:00:00 2001 From: Zhixing Zhang Date: Mon, 3 Apr 2023 14:23:26 -0700 Subject: [PATCH] Make bevy_render an optional dependency of bevy_scene (#8136) # Objective bevy-scene does not have a reason to depend on bevy-render except to include the `Visibility` and `ComputedVisibility` components. Including that in the dependency chain is unnecessary for people not using `bevy_render`. Also fixed a problem where compilation fails when the `serialize` feature was not enabled. ## Solution This was added in #5335 to address some of the problems caused by #5310. Imo the user just always have to remember to include `VisibilityBundle` when they spawn `SceneBundle` or `DynamicSceneBundle`, but that will be a breaking change. This PR makes `bevy_render` an optional dependency of `bevy_scene` instead to respect the existing behavior. --- crates/bevy_gltf/Cargo.toml | 2 +- crates/bevy_internal/Cargo.toml | 1 + crates/bevy_scene/Cargo.toml | 2 +- crates/bevy_scene/src/bundle.rs | 7 +++++++ crates/bevy_scene/src/scene_loader.rs | 1 + 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/bevy_gltf/Cargo.toml b/crates/bevy_gltf/Cargo.toml index d55b477efeb19..ca79831f5b8fa 100644 --- a/crates/bevy_gltf/Cargo.toml +++ b/crates/bevy_gltf/Cargo.toml @@ -22,7 +22,7 @@ bevy_math = { path = "../bevy_math", version = "0.11.0-dev" } bevy_pbr = { path = "../bevy_pbr", version = "0.11.0-dev" } bevy_reflect = { path = "../bevy_reflect", version = "0.11.0-dev", features = ["bevy"] } bevy_render = { path = "../bevy_render", version = "0.11.0-dev" } -bevy_scene = { path = "../bevy_scene", version = "0.11.0-dev" } +bevy_scene = { path = "../bevy_scene", version = "0.11.0-dev", features = ["bevy_render"] } bevy_transform = { path = "../bevy_transform", version = "0.11.0-dev" } bevy_tasks = { path = "../bevy_tasks", version = "0.11.0-dev" } bevy_utils = { path = "../bevy_utils", version = "0.11.0-dev" } diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index 2c4439b1be34a..fea2205f39a18 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -92,6 +92,7 @@ accesskit_unix = ["bevy_winit/accesskit_unix"] bevy_text = ["dep:bevy_text", "bevy_ui?/bevy_text"] +bevy_render = ["dep:bevy_render", "bevy_scene?/bevy_render"] # Enable assertions to check the validity of parameters passed to glam glam_assert = ["bevy_math/glam_assert"] diff --git a/crates/bevy_scene/Cargo.toml b/crates/bevy_scene/Cargo.toml index 4ff56f014b7f2..86a40b7ed75a2 100644 --- a/crates/bevy_scene/Cargo.toml +++ b/crates/bevy_scene/Cargo.toml @@ -22,7 +22,7 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.11.0-dev", features = [" bevy_hierarchy = { path = "../bevy_hierarchy", version = "0.11.0-dev" } bevy_transform = { path = "../bevy_transform", version = "0.11.0-dev" } bevy_utils = { path = "../bevy_utils", version = "0.11.0-dev" } -bevy_render = { path = "../bevy_render", version = "0.11.0-dev" } +bevy_render = { path = "../bevy_render", version = "0.11.0-dev", optional = true } # other serde = { version = "1.0", features = ["derive"], optional = true } diff --git a/crates/bevy_scene/src/bundle.rs b/crates/bevy_scene/src/bundle.rs index e29498b02486c..1e66e5729325a 100644 --- a/crates/bevy_scene/src/bundle.rs +++ b/crates/bevy_scene/src/bundle.rs @@ -7,6 +7,7 @@ use bevy_ecs::{ prelude::{Changed, Component, Without}, system::{Commands, Query}, }; +#[cfg(feature = "bevy_render")] use bevy_render::prelude::{ComputedVisibility, Visibility}; use bevy_transform::components::{GlobalTransform, Transform}; @@ -27,7 +28,10 @@ pub struct SceneBundle { pub scene: Handle, pub transform: Transform, pub global_transform: GlobalTransform, + + #[cfg(feature = "bevy_render")] pub visibility: Visibility, + #[cfg(feature = "bevy_render")] pub computed_visibility: ComputedVisibility, } @@ -41,7 +45,10 @@ pub struct DynamicSceneBundle { pub scene: Handle, pub transform: Transform, pub global_transform: GlobalTransform, + + #[cfg(feature = "bevy_render")] pub visibility: Visibility, + #[cfg(feature = "bevy_render")] pub computed_visibility: ComputedVisibility, } diff --git a/crates/bevy_scene/src/scene_loader.rs b/crates/bevy_scene/src/scene_loader.rs index ed5c82443cc0f..ddffbebce454c 100644 --- a/crates/bevy_scene/src/scene_loader.rs +++ b/crates/bevy_scene/src/scene_loader.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "serialize")] use crate::serde::SceneDeserializer; use anyhow::{anyhow, Result}; use bevy_app::AppTypeRegistry;