Skip to content

Commit

Permalink
Make bevy_render an optional dependency of bevy_scene (#8136)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
Neo-Zhixing authored Apr 3, 2023
1 parent 086db6d commit 2aaaed7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_gltf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_scene/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
7 changes: 7 additions & 0 deletions crates/bevy_scene/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -27,7 +28,10 @@ pub struct SceneBundle {
pub scene: Handle<Scene>,
pub transform: Transform,
pub global_transform: GlobalTransform,

#[cfg(feature = "bevy_render")]
pub visibility: Visibility,
#[cfg(feature = "bevy_render")]
pub computed_visibility: ComputedVisibility,
}

Expand All @@ -41,7 +45,10 @@ pub struct DynamicSceneBundle {
pub scene: Handle<DynamicScene>,
pub transform: Transform,
pub global_transform: GlobalTransform,

#[cfg(feature = "bevy_render")]
pub visibility: Visibility,
#[cfg(feature = "bevy_render")]
pub computed_visibility: ComputedVisibility,
}

Expand Down
1 change: 1 addition & 0 deletions crates/bevy_scene/src/scene_loader.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "serialize")]
use crate::serde::SceneDeserializer;
use anyhow::{anyhow, Result};
use bevy_app::AppTypeRegistry;
Expand Down

0 comments on commit 2aaaed7

Please sign in to comment.