Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate bevy_transform to required components #14964

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0685690
remove GlobalTransform from engine bundles
ecoskey Aug 28, 2024
2c64297
allow deprecated reexport
ecoskey Aug 28, 2024
f3ae4fd
fix MaterialMeshletMeshBundle
ecoskey Aug 28, 2024
aacee1a
fix TransformBundle
ecoskey Aug 28, 2024
1d5f273
Update crates/bevy_transform/src/bundles.rs
ecoskey Aug 29, 2024
645a25f
fix docs
ecoskey Aug 29, 2024
88cffb5
Merge branch 'main' into migrate_transform
ecoskey Aug 29, 2024
d31ae68
format
ecoskey Aug 29, 2024
8f0b5e7
Merge branch 'migrate_transform' of github.com:ecoskey/bevy into migr…
ecoskey Aug 29, 2024
d013020
Merge branch 'main' into migrate_transform
ecoskey Aug 30, 2024
84af56d
fix error docs
ecoskey Sep 2, 2024
830a446
Merge branch 'main' into migrate_transform
ecoskey Sep 2, 2024
9706640
Update crates/bevy_transform/src/bundles.rs
ecoskey Sep 3, 2024
6ba0af9
Update errors/B0004.md
ecoskey Sep 3, 2024
8f2c879
Revert "fix TransformBundle"
ecoskey Sep 3, 2024
d86f1cb
Revert "fix MaterialMeshletMeshBundle"
ecoskey Sep 3, 2024
7be3846
fix unnecessary bits
ecoskey Sep 3, 2024
3ed3d47
Merge branch 'migrate_transform' of github.com:ecoskey/bevy into migr…
ecoskey Sep 3, 2024
a35ea69
Merge branch 'main' into migrate_transform
ecoskey Sep 3, 2024
6d58475
oops
ecoskey Sep 3, 2024
a4016b6
Merge branch 'migrate_transform' of github.com:ecoskey/bevy into migr…
ecoskey Sep 3, 2024
2270b3b
fix docs
ecoskey Sep 3, 2024
9524f69
Merge branch 'main' into migrate_transform
ecoskey Sep 5, 2024
3b8d602
fix the require
ecoskey Sep 5, 2024
ce53370
I am dumb
ecoskey Sep 5, 2024
c3b6efa
bump MSRV
ecoskey Sep 8, 2024
91c7d9e
use new expect lints
ecoskey Sep 8, 2024
6040936
Merge branch 'main' into migrate_transform
ecoskey Sep 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_transform/src/bundles.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![expect(deprecated)]
use bevy_ecs::bundle::Bundle;

use crate::prelude::{GlobalTransform, Transform};
Expand All @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_transform/src/components/global_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`]
///
Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_transform/src/components/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`]
///
Expand All @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_transform/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ mod tests {
use bevy_math::{Quat, Vec3};

use crate::{
bundles::TransformBundle,
components::{GlobalTransform, Transform},
helper::TransformHelper,
plugins::TransformPlugin,
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
60 changes: 17 additions & 43 deletions crates/bevy_transform/src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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));
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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();
})
Expand Down Expand Up @@ -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)
Expand All @@ -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::<Parent>(child).unwrap(),
Expand All @@ -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();
Expand Down
14 changes: 5 additions & 9 deletions errors/B0004.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn setup_cube(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands
.spawn(TransformBundle::default())
.spawn(Transform::default())
.with_children(|parent| {
// cube
parent.spawn(PbrBundle {
Expand Down Expand Up @@ -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::*;
Expand All @@ -73,7 +72,7 @@ fn setup_cube(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
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())
Expand Down Expand Up @@ -103,18 +102,15 @@ 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.

[`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
10 changes: 2 additions & 8 deletions examples/animation/custom_skinned_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion examples/asset/asset_decompression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
..default()
},
Sprite::default(),
TransformBundle::default(),
Transform::default(),
VisibilityBundle::default(),
));
}
Expand Down
4 changes: 2 additions & 2 deletions examples/stress_tests/transform_hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()
};
Expand Down