Skip to content

Commit bdd0af6

Browse files
authored
Deprecate SpatialBundle (#15830)
# Objective - Required components replace bundles, but `SpatialBundle` is yet to be deprecated ## Solution - Deprecate `SpatialBundle` - Insert `Transform` and `Visibility` instead in examples using it - In `spawn` or `insert` inserting a default `Transform` or `Visibility` with component already requiring either, remove those components from the tuple ## Testing - Did you test these changes? If so, how? Yes, I ran the examples I changed and tests - Are there any parts that need more testing? The `gamepad_viewer` and and `custom_shader_instancing` examples don't work as intended due to entirely unrelated code, didn't check main. - How can other people (reviewers) test your changes? Is there anything specific they need to know? Run examples, or just check that all spawned values are identical - If relevant, what platforms did you test these changes on, and are there any important ones you can't test? Linux, wayland trough x11 (cause that's the default feature) --- ## Migration Guide `SpatialBundle` is now deprecated, insert `Transform` and `Visibility` instead which will automatically insert all other components that were in the bundle. If you do not specify these values and any other components in your `spawn`/`insert` call already requires either of these components you can leave that one out. before: ```rust commands.spawn(SpatialBundle::default()); ``` after: ```rust commands.spawn((Transform::default(), Visibility::default()); ```
1 parent 0720e62 commit bdd0af6

19 files changed

+67
-103
lines changed

crates/bevy_gltf/src/loader.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ use bevy_render::{
2828
skinning::{SkinnedMesh, SkinnedMeshInverseBindposes},
2929
Indices, Mesh, Mesh3d, MeshVertexAttribute, VertexAttributeValues,
3030
},
31-
prelude::SpatialBundle,
3231
primitives::Aabb,
3332
render_asset::RenderAssetUsages,
3433
render_resource::{Face, PrimitiveTopology},
3534
texture::{
3635
CompressedImageFormats, Image, ImageAddressMode, ImageFilterMode, ImageLoaderSettings,
3736
ImageSampler, ImageSamplerDescriptor, ImageType, TextureError,
3837
},
38+
view::Visibility,
3939
};
4040
use bevy_scene::Scene;
4141
#[cfg(not(target_arch = "wasm32"))]
@@ -822,7 +822,7 @@ async fn load_gltf<'a, 'b, 'c>(
822822
let mut scene_load_context = load_context.begin_labeled_asset();
823823

824824
let world_root_id = world
825-
.spawn(SpatialBundle::INHERITED_IDENTITY)
825+
.spawn((Transform::default(), Visibility::default()))
826826
.with_children(|parent| {
827827
for node in scene.nodes() {
828828
let result = load_node(
@@ -1359,7 +1359,7 @@ fn load_node(
13591359
// of negative scale factors is odd. if so we will assign a copy of the material with face
13601360
// culling inverted, rather than modifying the mesh data directly.
13611361
let is_scale_inverted = world_transform.scale.is_negative_bitmask().count_ones() & 1 == 1;
1362-
let mut node = world_builder.spawn(SpatialBundle::from(transform));
1362+
let mut node = world_builder.spawn((transform, Visibility::default()));
13631363

13641364
let name = node_name(gltf_node);
13651365
node.insert(name.clone());

crates/bevy_render/src/spatial_bundle.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![expect(deprecated)]
12
use bevy_ecs::prelude::Bundle;
23
use bevy_transform::prelude::{GlobalTransform, Transform};
34

@@ -16,6 +17,12 @@ use crate::view::{InheritedVisibility, ViewVisibility, Visibility};
1617
///
1718
/// [`Component`]: bevy_ecs::component::Component
1819
#[derive(Bundle, Clone, Debug, Default)]
20+
#[deprecated(
21+
since = "0.15.0",
22+
note = "Use the `Transform` and `Visibility` components instead.
23+
Inserting `Transform` will now also insert a `GlobalTransform` automatically.
24+
Inserting 'Visibility' will now also insert `InheritedVisibility` and `ViewVisibility` automatically."
25+
)]
1926
pub struct SpatialBundle {
2027
/// The visibility of the entity.
2128
pub visibility: Visibility,

examples/2d/bounding_2d.rs

+6-24
Original file line numberDiff line numberDiff line change
@@ -203,31 +203,22 @@ const OFFSET_Y: f32 = 75.;
203203
fn setup(mut commands: Commands) {
204204
commands.spawn(Camera2d);
205205
commands.spawn((
206-
SpatialBundle {
207-
transform: Transform::from_xyz(-OFFSET_X, OFFSET_Y, 0.),
208-
..default()
209-
},
206+
Transform::from_xyz(-OFFSET_X, OFFSET_Y, 0.),
210207
Shape::Circle(Circle::new(45.)),
211208
DesiredVolume::Aabb,
212209
Intersects::default(),
213210
));
214211

215212
commands.spawn((
216-
SpatialBundle {
217-
transform: Transform::from_xyz(0., OFFSET_Y, 0.),
218-
..default()
219-
},
213+
Transform::from_xyz(0., OFFSET_Y, 0.),
220214
Shape::Rectangle(Rectangle::new(80., 80.)),
221215
Spin,
222216
DesiredVolume::Circle,
223217
Intersects::default(),
224218
));
225219

226220
commands.spawn((
227-
SpatialBundle {
228-
transform: Transform::from_xyz(OFFSET_X, OFFSET_Y, 0.),
229-
..default()
230-
},
221+
Transform::from_xyz(OFFSET_X, OFFSET_Y, 0.),
231222
Shape::Triangle(Triangle2d::new(
232223
Vec2::new(-40., -40.),
233224
Vec2::new(-20., 40.),
@@ -239,32 +230,23 @@ fn setup(mut commands: Commands) {
239230
));
240231

241232
commands.spawn((
242-
SpatialBundle {
243-
transform: Transform::from_xyz(-OFFSET_X, -OFFSET_Y, 0.),
244-
..default()
245-
},
233+
Transform::from_xyz(-OFFSET_X, -OFFSET_Y, 0.),
246234
Shape::Line(Segment2d::new(Dir2::from_xy(1., 0.3).unwrap(), 90.)),
247235
Spin,
248236
DesiredVolume::Circle,
249237
Intersects::default(),
250238
));
251239

252240
commands.spawn((
253-
SpatialBundle {
254-
transform: Transform::from_xyz(0., -OFFSET_Y, 0.),
255-
..default()
256-
},
241+
Transform::from_xyz(0., -OFFSET_Y, 0.),
257242
Shape::Capsule(Capsule2d::new(25., 50.)),
258243
Spin,
259244
DesiredVolume::Aabb,
260245
Intersects::default(),
261246
));
262247

263248
commands.spawn((
264-
SpatialBundle {
265-
transform: Transform::from_xyz(OFFSET_X, -OFFSET_Y, 0.),
266-
..default()
267-
},
249+
Transform::from_xyz(OFFSET_X, -OFFSET_Y, 0.),
268250
Shape::Polygon(RegularPolygon::new(50., 6)),
269251
Spin,
270252
DesiredVolume::Circle,

examples/2d/mesh2d_manual.rs

-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ fn star(
110110
ColoredMesh2d,
111111
// The `Handle<Mesh>` needs to be wrapped in a `Mesh2d` for 2D rendering
112112
Mesh2d(meshes.add(star)),
113-
// This bundle's components are needed for something to be rendered
114-
SpatialBundle::INHERITED_IDENTITY,
115113
));
116114

117115
// Spawn the camera

examples/3d/fog_volumes.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,17 @@ fn main() {
3030
/// Spawns all the objects in the scene.
3131
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
3232
// Spawn a fog volume with a voxelized version of the Stanford bunny.
33-
commands
34-
.spawn(SpatialBundle {
35-
visibility: Visibility::Visible,
36-
transform: Transform::from_xyz(0.0, 0.5, 0.0),
37-
..default()
38-
})
39-
.insert(FogVolume {
33+
commands.spawn((
34+
Transform::from_xyz(0.0, 0.5, 0.0),
35+
FogVolume {
4036
density_texture: Some(asset_server.load("volumes/bunny.ktx2")),
4137
density_factor: 1.0,
4238
// Scatter as much of the light as possible, to brighten the bunny
4339
// up.
4440
scattering: 1.0,
4541
..default()
46-
});
42+
},
43+
));
4744

4845
// Spawn a bright directional light that illuminates the fog well.
4946
commands.spawn((

examples/3d/irradiance_volumes.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,14 @@ fn spawn_camera(commands: &mut Commands, assets: &ExampleAssets) {
243243
}
244244

245245
fn spawn_irradiance_volume(commands: &mut Commands, assets: &ExampleAssets) {
246-
commands
247-
.spawn(SpatialBundle {
248-
transform: Transform::from_matrix(VOXEL_FROM_WORLD),
249-
..SpatialBundle::default()
250-
})
251-
.insert(IrradianceVolume {
246+
commands.spawn((
247+
Transform::from_matrix(VOXEL_FROM_WORLD),
248+
IrradianceVolume {
252249
voxels: assets.irradiance_volume.clone(),
253250
intensity: IRRADIANCE_VOLUME_INTENSITY,
254-
})
255-
.insert(LightProbe);
251+
},
252+
LightProbe,
253+
));
256254
}
257255

258256
fn spawn_light(commands: &mut Commands) {
@@ -277,12 +275,7 @@ fn spawn_sphere(commands: &mut Commands, assets: &ExampleAssets) {
277275
}
278276

279277
fn spawn_voxel_cube_parent(commands: &mut Commands) {
280-
commands
281-
.spawn(SpatialBundle {
282-
visibility: Visibility::Hidden,
283-
..default()
284-
})
285-
.insert(VoxelCubeParent);
278+
commands.spawn((Visibility::Hidden, Transform::default(), VoxelCubeParent));
286279
}
287280

288281
fn spawn_fox(commands: &mut Commands, assets: &ExampleAssets) {

examples/3d/scrolling_fog.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,7 @@ fn setup(
113113

114114
// Spawn a FogVolume and use the repeating noise texture as its density texture.
115115
commands.spawn((
116-
SpatialBundle {
117-
visibility: Visibility::Visible,
118-
transform: Transform::from_xyz(0.0, 32.0, 0.0).with_scale(Vec3::splat(64.0)),
119-
..default()
120-
},
116+
Transform::from_xyz(0.0, 32.0, 0.0).with_scale(Vec3::splat(64.0)),
121117
FogVolume {
122118
density_texture: Some(noise_texture),
123119
density_factor: 0.05,

examples/3d/shadow_biases.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,7 @@ fn setup(
4646

4747
let light_transform = Transform::from_xyz(5.0, 5.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y);
4848
commands
49-
.spawn((
50-
SpatialBundle {
51-
transform: light_transform,
52-
..default()
53-
},
54-
Lights,
55-
))
49+
.spawn((light_transform, Visibility::default(), Lights))
5650
.with_children(|builder| {
5751
builder.spawn(PointLight {
5852
intensity: 0.0,

examples/animation/animated_transform.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ fn setup(
151151
.with_children(|p| {
152152
// This entity is just used for animation, but doesn't display anything
153153
p.spawn((
154-
SpatialBundle::INHERITED_IDENTITY,
154+
Transform::default(),
155+
Visibility::default(),
155156
orbit_controller,
156157
AnimationTarget {
157158
id: orbit_controller_animation_target_id,

examples/audio/spatial_audio_2d.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ fn setup(
4444

4545
let listener = SpatialListener::new(gap);
4646
commands
47-
.spawn((SpatialBundle::default(), listener.clone()))
47+
.spawn((
48+
Transform::default(),
49+
Visibility::default(),
50+
listener.clone(),
51+
))
4852
.with_children(|parent| {
4953
// left ear
5054
parent.spawn((

examples/audio/spatial_audio_3d.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ fn setup(
3535

3636
let listener = SpatialListener::new(gap);
3737
commands
38-
.spawn((SpatialBundle::default(), listener.clone()))
38+
.spawn((
39+
Transform::default(),
40+
Visibility::default(),
41+
listener.clone(),
42+
))
3943
.with_children(|parent| {
4044
// left ear indicator
4145
parent.spawn((

examples/camera/first_person_view_model.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,8 @@ fn spawn_view_model(
108108
.spawn((
109109
Player,
110110
CameraSensitivity::default(),
111-
SpatialBundle {
112-
transform: Transform::from_xyz(0.0, 1.0, 0.0),
113-
..default()
114-
},
111+
Transform::from_xyz(0.0, 1.0, 0.0),
112+
Visibility::default(),
115113
))
116114
.with_children(|parent| {
117115
parent.spawn((

examples/games/desk_toy.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ fn setup(
146146

147147
// sclera
148148
commands
149-
.spawn(SpatialBundle::from_transform(Transform::from_xyz(
150-
x, y, 2.0,
151-
)))
149+
.spawn((Transform::from_xyz(x, y, 2.0), Visibility::default()))
152150
.with_children(|commands| {
153151
// sclera
154152
commands.spawn((
@@ -163,7 +161,8 @@ fn setup(
163161
// pupil
164162
commands
165163
.spawn((
166-
SpatialBundle::from_transform(Transform::from_xyz(0.0, 0.0, 1.0)),
164+
Transform::from_xyz(0.0, 0.0, 1.0),
165+
Visibility::default(),
167166
Pupil {
168167
eye_radius: radius,
169168
pupil_radius,

examples/picking/sprite_picking.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
3535
let sprite_size = Vec2::splat(len / 2.0);
3636

3737
commands
38-
.spawn(SpatialBundle::default())
38+
.spawn((Transform::default(), Visibility::default()))
3939
.with_children(|commands| {
4040
for (anchor_index, anchor) in [
4141
Anchor::TopLeft,

examples/shader/custom_phase_item.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,16 @@ fn main() {
198198
fn setup(mut commands: Commands) {
199199
// Spawn a single entity that has custom rendering. It'll be extracted into
200200
// the render world via [`ExtractComponent`].
201-
commands
202-
.spawn(SpatialBundle {
203-
visibility: Visibility::Visible,
204-
transform: Transform::IDENTITY,
205-
..default()
206-
})
201+
commands.spawn((
202+
Visibility::default(),
203+
Transform::default(),
207204
// This `Aabb` is necessary for the visibility checks to work.
208-
.insert(Aabb {
205+
Aabb {
209206
center: Vec3A::ZERO,
210207
half_extents: Vec3A::splat(0.5),
211-
})
212-
.insert(CustomRenderedEntity);
208+
},
209+
CustomRenderedEntity,
210+
));
213211

214212
// Spawn the camera.
215213
commands.spawn((

examples/shader/custom_shader_instancing.rs

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ fn main() {
4949
fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
5050
commands.spawn((
5151
Mesh3d(meshes.add(Cuboid::new(0.5, 0.5, 0.5))),
52-
SpatialBundle::INHERITED_IDENTITY,
5352
InstanceMaterialData(
5453
(1..=10)
5554
.flat_map(|x| (1..=10).map(move |y| (x as f32 / 10.0, y as f32 / 10.0)))

examples/shader/specialized_mesh_pipeline.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@ fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
8080
CustomRenderedEntity,
8181
// We need to add the mesh handle to the entity
8282
Mesh3d(meshes.add(mesh.clone())),
83-
// This bundle's components are needed for something to be rendered
84-
SpatialBundle {
85-
transform: Transform::from_xyz(x, y, 0.0),
86-
..SpatialBundle::INHERITED_IDENTITY
87-
},
83+
Transform::from_xyz(x, y, 0.0),
8884
));
8985
}
9086

examples/stress_tests/many_foxes.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ fn setup(
156156
let (base_rotation, ring_direction) = ring_directions[ring_index % 2];
157157
let ring_parent = commands
158158
.spawn((
159-
SpatialBundle::INHERITED_IDENTITY,
159+
Transform::default(),
160+
Visibility::default(),
160161
ring_direction,
161162
Ring { radius },
162163
))

0 commit comments

Comments
 (0)