diff --git a/Cargo.toml b/Cargo.toml index 4112429b3ed9a..0924fc05c06dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ keywords = ["game", "engine", "gamedev", "graphics", "bevy"] license = "MIT OR Apache-2.0" repository = "https://github.com/bevyengine/bevy" documentation = "https://docs.rs/bevy" -rust-version = "1.79.0" +rust-version = "1.81.0" [workspace] exclude = [ diff --git a/crates/bevy_transform/src/bundles.rs b/crates/bevy_transform/src/bundles.rs index dc8931824a7fd..34b05ec6518d9 100644 --- a/crates/bevy_transform/src/bundles.rs +++ b/crates/bevy_transform/src/bundles.rs @@ -1,3 +1,4 @@ +#![expect(deprecated)] use bevy_ecs::bundle::Bundle; use crate::prelude::{GlobalTransform, Transform}; @@ -24,6 +25,10 @@ use crate::prelude::{GlobalTransform, Transform}; /// update the [`Transform`] of an entity in this schedule or after, you will notice a 1 frame lag /// before the [`GlobalTransform`] is updated. #[derive(Clone, Copy, Debug, Default, Bundle)] +#[deprecated( + since = "0.15.0", + note = "Use the `Transform` component instead. Inserting `Transform` will now also insert a `GlobalTransform` automatically." +)] pub struct TransformBundle { /// The transform of the entity. pub local: Transform, diff --git a/crates/bevy_transform/src/components/global_transform.rs b/crates/bevy_transform/src/components/global_transform.rs index dd8f4ca08f5a3..ac2e62e5defc7 100644 --- a/crates/bevy_transform/src/components/global_transform.rs +++ b/crates/bevy_transform/src/components/global_transform.rs @@ -14,7 +14,9 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect}; /// /// * To get the global transform of an entity, you should get its [`GlobalTransform`]. /// * For transform hierarchies to work correctly, you must have both a [`Transform`] and a [`GlobalTransform`]. -/// * You may use the [`TransformBundle`](crate::bundles::TransformBundle) to guarantee this. +/// ~* You may use the [`TransformBundle`](crate::bundles::TransformBundle) to guarantee this.~ +/// * [`TransformBundle`](crate::bundles::TransformBundle) is now deprecated. +/// [`GlobalTransform`] is automatically inserted whenever [`Transform`] is inserted. /// /// ## [`Transform`] and [`GlobalTransform`] /// diff --git a/crates/bevy_transform/src/components/transform.rs b/crates/bevy_transform/src/components/transform.rs index f0d89017454d3..9ec1081893abe 100644 --- a/crates/bevy_transform/src/components/transform.rs +++ b/crates/bevy_transform/src/components/transform.rs @@ -12,7 +12,9 @@ use std::ops::Mul; /// * To place or move an entity, you should set its [`Transform`]. /// * To get the global transform of an entity, you should get its [`GlobalTransform`]. /// * To be displayed, an entity must have both a [`Transform`] and a [`GlobalTransform`]. -/// * You may use the [`TransformBundle`](crate::bundles::TransformBundle) to guarantee this. +/// ~* You may use the [`TransformBundle`](crate::bundles::TransformBundle) to guarantee this.~ +/// * [`TransformBundle`](crate::bundles::TransformBundle) is now deprecated. +/// [`GlobalTransform`] is inserted automatically whenever [`Transform`] is inserted. /// /// ## [`Transform`] and [`GlobalTransform`] /// @@ -38,6 +40,7 @@ use std::ops::Mul; #[cfg_attr( feature = "bevy-support", derive(Component, Reflect), + require(GlobalTransform), reflect(Component, Default, PartialEq) )] pub struct Transform { diff --git a/crates/bevy_transform/src/helper.rs b/crates/bevy_transform/src/helper.rs index 091e39e189bac..bca33a933f3e8 100644 --- a/crates/bevy_transform/src/helper.rs +++ b/crates/bevy_transform/src/helper.rs @@ -88,7 +88,6 @@ mod tests { use bevy_math::{Quat, Vec3}; use crate::{ - bundles::TransformBundle, components::{GlobalTransform, Transform}, helper::TransformHelper, plugins::TransformPlugin, @@ -122,7 +121,7 @@ mod tests { let mut entity = None; for transform in transforms { - let mut e = app.world_mut().spawn(TransformBundle::from(transform)); + let mut e = app.world_mut().spawn(transform); if let Some(entity) = entity { e.set_parent(entity); diff --git a/crates/bevy_transform/src/lib.rs b/crates/bevy_transform/src/lib.rs index c6f55362924bd..9db2028b93576 100644 --- a/crates/bevy_transform/src/lib.rs +++ b/crates/bevy_transform/src/lib.rs @@ -32,6 +32,8 @@ pub mod systems; /// The transform prelude. /// /// This includes the most common types in this crate, re-exported for your convenience. +#[doc(hidden)] +#[expect(deprecated)] pub mod prelude { #[doc(hidden)] pub use crate::components::*; diff --git a/crates/bevy_transform/src/systems.rs b/crates/bevy_transform/src/systems.rs index f32a19dc42982..6262648b95dad 100644 --- a/crates/bevy_transform/src/systems.rs +++ b/crates/bevy_transform/src/systems.rs @@ -188,7 +188,6 @@ mod test { use bevy_math::{vec3, Vec3}; use bevy_tasks::{ComputeTaskPool, TaskPool}; - use crate::bundles::TransformBundle; use crate::systems::*; use bevy_hierarchy::{BuildChildren, ChildBuild}; @@ -198,8 +197,7 @@ mod test { let mut world = World::default(); let offset_global_transform = |offset| GlobalTransform::from(Transform::from_xyz(offset, offset, offset)); - let offset_transform = - |offset| TransformBundle::from_transform(Transform::from_xyz(offset, offset, offset)); + let offset_transform = |offset| Transform::from_xyz(offset, offset, offset); let mut schedule = Schedule::default(); schedule.add_systems((sync_simple_transforms, propagate_transforms)); @@ -256,22 +254,14 @@ mod test { schedule.add_systems((sync_simple_transforms, propagate_transforms)); // Root entity - world.spawn(TransformBundle::from(Transform::from_xyz(1.0, 0.0, 0.0))); + world.spawn(Transform::from_xyz(1.0, 0.0, 0.0)); let mut children = Vec::new(); world - .spawn(TransformBundle::from(Transform::from_xyz(1.0, 0.0, 0.0))) + .spawn(Transform::from_xyz(1.0, 0.0, 0.0)) .with_children(|parent| { - children.push( - parent - .spawn(TransformBundle::from(Transform::from_xyz(0.0, 2.0, 0.))) - .id(), - ); - children.push( - parent - .spawn(TransformBundle::from(Transform::from_xyz(0.0, 0.0, 3.))) - .id(), - ); + children.push(parent.spawn(Transform::from_xyz(0.0, 2.0, 0.)).id()); + children.push(parent.spawn(Transform::from_xyz(0.0, 0.0, 3.)).id()); }); schedule.run(&mut world); @@ -298,18 +288,10 @@ mod test { let mut commands = Commands::new(&mut queue, &world); let mut children = Vec::new(); commands - .spawn(TransformBundle::from(Transform::from_xyz(1.0, 0.0, 0.0))) + .spawn(Transform::from_xyz(1.0, 0.0, 0.0)) .with_children(|parent| { - children.push( - parent - .spawn(TransformBundle::from(Transform::from_xyz(0.0, 2.0, 0.0))) - .id(), - ); - children.push( - parent - .spawn(TransformBundle::from(Transform::from_xyz(0.0, 0.0, 3.0))) - .id(), - ); + children.push(parent.spawn(Transform::from_xyz(0.0, 2.0, 0.0)).id()); + children.push(parent.spawn(Transform::from_xyz(0.0, 0.0, 3.0)).id()); }); queue.apply(&mut world); schedule.run(&mut world); @@ -416,15 +398,12 @@ mod test { let mut grandchild = Entity::from_raw(1); let parent = app .world_mut() - .spawn(( - Transform::from_translation(translation), - GlobalTransform::IDENTITY, - )) + .spawn(Transform::from_translation(translation)) .with_children(|builder| { child = builder - .spawn(TransformBundle::IDENTITY) + .spawn(Transform::IDENTITY) .with_children(|builder| { - grandchild = builder.spawn(TransformBundle::IDENTITY).id(); + grandchild = builder.spawn(Transform::IDENTITY).id(); }) .id(); }) @@ -461,9 +440,9 @@ mod test { fn setup_world(world: &mut World) -> (Entity, Entity) { let mut grandchild = Entity::from_raw(0); let child = world - .spawn(TransformBundle::IDENTITY) + .spawn(Transform::IDENTITY) .with_children(|builder| { - grandchild = builder.spawn(TransformBundle::IDENTITY).id(); + grandchild = builder.spawn(Transform::IDENTITY).id(); }) .id(); (child, grandchild) @@ -476,7 +455,7 @@ mod test { assert_eq!(temp_grandchild, grandchild); app.world_mut() - .spawn(TransformBundle::IDENTITY) + .spawn(Transform::IDENTITY) .push_children(&[child]); std::mem::swap( &mut *app.world_mut().get_mut::(child).unwrap(), @@ -495,14 +474,9 @@ mod test { let mut schedule = Schedule::default(); schedule.add_systems((sync_simple_transforms, propagate_transforms)); - // Spawn a `TransformBundle` entity with a local translation of `Vec3::ONE` - let mut spawn_transform_bundle = || { - world - .spawn(TransformBundle::from_transform( - Transform::from_translation(translation), - )) - .id() - }; + // Spawn a `Transform` entity with a local translation of `Vec3::ONE` + let mut spawn_transform_bundle = + || world.spawn(Transform::from_translation(translation)).id(); // Spawn parent and child with identical transform bundles let parent = spawn_transform_bundle(); diff --git a/errors/B0004.md b/errors/B0004.md index 5cf94109bfa51..0d81c0b3cd4e8 100644 --- a/errors/B0004.md +++ b/errors/B0004.md @@ -29,7 +29,7 @@ fn setup_cube( mut materials: ResMut>, ) { commands - .spawn(TransformBundle::default()) + .spawn(Transform::default()) .with_children(|parent| { // cube parent.spawn(PbrBundle { @@ -61,8 +61,7 @@ doesn't have a [`ViewVisibility`] or [`InheritedVisibility`] component. Since the cube is spawned as a child of an entity without the visibility components, it will not be visible at all. -To fix this, you must use [`SpatialBundle`] over [`TransformBundle`], -as follows: +To fix this, you must use [`SpatialBundle`], as follows: ```rust,no_run use bevy::prelude::*; @@ -73,7 +72,7 @@ fn setup_cube( mut materials: ResMut>, ) { commands - // We use SpatialBundle instead of TransformBundle, it contains the + // We use SpatialBundle instead of Transform, it contains the // visibility components needed to display the cube, // In addition to the Transform and GlobalTransform components. .spawn(SpatialBundle::default()) @@ -103,9 +102,8 @@ fn main() { ``` A similar problem occurs when the [`GlobalTransform`] component is missing. -However, when a parent [`GlobalTransform`] is missing, -it will simply prevent all transform propagation, -including when updating the [`Transform`] component of the child. +However, it will be automatically inserted whenever `Transform` is +inserted, as it's a required component. You will most likely encounter this warning when loading a scene as a child of a pre-existing [`Entity`] that does not have the proper components. @@ -113,8 +111,6 @@ as a child of a pre-existing [`Entity`] that does not have the proper components [`InheritedVisibility`]: https://docs.rs/bevy/*/bevy/render/view/struct.InheritedVisibility.html [`ViewVisibility`]: https://docs.rs/bevy/*/bevy/render/view/struct.ViewVisibility.html [`GlobalTransform`]: https://docs.rs/bevy/*/bevy/transform/components/struct.GlobalTransform.html -[`Transform`]: https://docs.rs/bevy/*/bevy/transform/components/struct.Transform.html [`Parent`]: https://docs.rs/bevy/*/bevy/hierarchy/struct.Parent.html [`Entity`]: https://docs.rs/bevy/*/bevy/ecs/entity/struct.Entity.html [`SpatialBundle`]: https://docs.rs/bevy/*/bevy/render/prelude/struct.SpatialBundle.html -[`TransformBundle`]: https://docs.rs/bevy/*/bevy/transform/struct.TransformBundle.html diff --git a/examples/animation/custom_skinned_mesh.rs b/examples/animation/custom_skinned_mesh.rs index 8c37e3b9568e6..25dd59e28dd2c 100644 --- a/examples/animation/custom_skinned_mesh.rs +++ b/examples/animation/custom_skinned_mesh.rs @@ -129,15 +129,9 @@ fn setup( for i in -5..5 { // Create joint entities let joint_0 = commands - .spawn(TransformBundle::from(Transform::from_xyz( - i as f32 * 1.5, - 0.0, - i as f32 * 0.1, - ))) - .id(); - let joint_1 = commands - .spawn((AnimatedJoint, TransformBundle::IDENTITY)) + .spawn(Transform::from_xyz(i as f32 * 1.5, 0.0, i as f32 * 0.1)) .id(); + let joint_1 = commands.spawn((AnimatedJoint, Transform::IDENTITY)).id(); // Set joint_1 as a child of joint_0. commands.entity(joint_0).push_children(&[joint_1]); diff --git a/examples/asset/asset_decompression.rs b/examples/asset/asset_decompression.rs index 4101d24bb2008..71d177f874ddf 100644 --- a/examples/asset/asset_decompression.rs +++ b/examples/asset/asset_decompression.rs @@ -112,7 +112,7 @@ fn setup(mut commands: Commands, asset_server: Res) { ..default() }, Sprite::default(), - TransformBundle::default(), + Transform::default(), VisibilityBundle::default(), )); } diff --git a/examples/stress_tests/transform_hierarchy.rs b/examples/stress_tests/transform_hierarchy.rs index 0b95d5705d883..029ecfc3bca88 100644 --- a/examples/stress_tests/transform_hierarchy.rs +++ b/examples/stress_tests/transform_hierarchy.rs @@ -380,7 +380,7 @@ fn spawn_tree( } // insert root - ents.push(commands.spawn(TransformBundle::from(root_transform)).id()); + ents.push(commands.spawn(root_transform).id()); let mut result = InsertResult::default(); let mut rng = rand::thread_rng(); @@ -426,7 +426,7 @@ fn spawn_tree( }; // only insert the components necessary for the transform propagation - cmd = cmd.insert(TransformBundle::from(transform)); + cmd = cmd.insert(transform); cmd.id() };