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.
This commit is contained in:
Zhixing Zhang 2023-04-03 14:23:26 -07:00 committed by GitHub
parent 086db6d22f
commit 2aaaed7f69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 2 deletions

View file

@ -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" }

View file

@ -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"]

View file

@ -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 }

View file

@ -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<Scene>,
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<DynamicScene>,
pub transform: Transform,
pub global_transform: GlobalTransform,
#[cfg(feature = "bevy_render")]
pub visibility: Visibility,
#[cfg(feature = "bevy_render")]
pub computed_visibility: ComputedVisibility,
}

View file

@ -1,3 +1,4 @@
#[cfg(feature = "serialize")]
use crate::serde::SceneDeserializer;
use anyhow::{anyhow, Result};
use bevy_app::AppTypeRegistry;