bevy_transform/bundles.rs
1#![expect(deprecated)]
2use bevy_ecs::bundle::Bundle;
3
4use crate::prelude::{GlobalTransform, Transform};
5
6/// A [`Bundle`] of the [`Transform`] and [`GlobalTransform`]
7/// [`Component`](bevy_ecs::component::Component)s, which describe the position of an entity.
8///
9/// * To place or move an entity, you should set its [`Transform`].
10/// * To get the global transform of an entity, you should get its [`GlobalTransform`].
11/// * For transform hierarchies to work correctly, you must have both a [`Transform`] and a [`GlobalTransform`].
12/// * ~You may use the [`TransformBundle`] to guarantee this.~
13/// [`TransformBundle`] is now deprecated.
14/// [`GlobalTransform`] is automatically inserted whenever [`Transform`] is inserted.
15///
16/// ## [`Transform`] and [`GlobalTransform`]
17///
18/// [`Transform`] is the position of an entity relative to its parent position, or the reference
19/// frame if it doesn't have a parent.
20///
21/// [`GlobalTransform`] is the position of an entity relative to the reference frame.
22///
23/// [`GlobalTransform`] is updated from [`Transform`] by systems in the system set
24/// [`TransformPropagate`](crate::TransformSystem::TransformPropagate).
25///
26/// This system runs during [`PostUpdate`](bevy_app::PostUpdate). If you
27/// update the [`Transform`] of an entity in this schedule or after, you will notice a 1 frame lag
28/// before the [`GlobalTransform`] is updated.
29#[derive(Clone, Copy, Debug, Default, Bundle)]
30#[deprecated(
31 since = "0.15.0",
32 note = "Use the `Transform` component instead. Inserting `Transform` will now also insert a `GlobalTransform` automatically."
33)]
34pub struct TransformBundle {
35 /// The transform of the entity.
36 pub local: Transform,
37 /// The global transform of the entity.
38 pub global: GlobalTransform,
39}
40
41impl TransformBundle {
42 /// An identity [`TransformBundle`] with no translation, rotation, and a scale of 1 on all axes.
43 pub const IDENTITY: Self = TransformBundle {
44 local: Transform::IDENTITY,
45 global: GlobalTransform::IDENTITY,
46 };
47
48 /// Creates a new [`TransformBundle`] from a [`Transform`].
49 ///
50 /// This initializes [`GlobalTransform`] as identity, to be updated later by the
51 /// [`bevy_app::PostUpdate`] schedule.
52 #[inline]
53 pub const fn from_transform(transform: Transform) -> Self {
54 TransformBundle {
55 local: transform,
56 ..Self::IDENTITY
57 }
58 }
59}
60
61impl From<Transform> for TransformBundle {
62 #[inline]
63 fn from(transform: Transform) -> Self {
64 Self::from_transform(transform)
65 }
66}