mirror of
https://github.com/bevyengine/bevy
synced 2024-12-24 20:13:07 +00:00
39d6a745d2
# Objective The next step in the migration to required components: Deprecate `VisibilityBundle` and make `Visibility` require `InheritedVisibility` and `ViewVisibility`, as per the [chosen proposal](https://hackmd.io/@bevy/required_components/%2FcO7JPSAQR5G0J_j5wNwtOQ). ## Solution Deprecate `VisibilityBundle` and make `Visibility` require `InheritedVisibility` and `ViewVisibility`. I chose not to deprecate `SpatialBundle` yet, as doing so would mean that we need to manually add `Visibility` to a bunch of places. It will be nicer once meshes, sprites, lights, fog, and cameras have been migrated, since they will require `Transform` and `Visibility` and therefore not need manually added defaults for them. --- ## Migration Guide Replace all insertions of `VisibilityBundle` with the `Visibility` component. The other components required by it will now be inserted automatically.
66 lines
2.5 KiB
Rust
66 lines
2.5 KiB
Rust
#![expect(deprecated)]
|
|
use bevy_ecs::bundle::Bundle;
|
|
|
|
use crate::prelude::{GlobalTransform, Transform};
|
|
|
|
/// A [`Bundle`] of the [`Transform`] and [`GlobalTransform`]
|
|
/// [`Component`](bevy_ecs::component::Component)s, which describe the position of an entity.
|
|
///
|
|
/// * To place or move an entity, you should set its [`Transform`].
|
|
/// * 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`] to guarantee this.~
|
|
/// [`TransformBundle`] is now deprecated.
|
|
/// [`GlobalTransform`] is automatically inserted whenever [`Transform`] is inserted.
|
|
///
|
|
/// ## [`Transform`] and [`GlobalTransform`]
|
|
///
|
|
/// [`Transform`] is the position of an entity relative to its parent position, or the reference
|
|
/// frame if it doesn't have a parent.
|
|
///
|
|
/// [`GlobalTransform`] is the position of an entity relative to the reference frame.
|
|
///
|
|
/// [`GlobalTransform`] is updated from [`Transform`] by systems in the system set
|
|
/// [`TransformPropagate`](crate::TransformSystem::TransformPropagate).
|
|
///
|
|
/// This system runs during [`PostUpdate`](bevy_app::PostUpdate). If you
|
|
/// 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,
|
|
/// The global transform of the entity.
|
|
pub global: GlobalTransform,
|
|
}
|
|
|
|
impl TransformBundle {
|
|
/// An identity [`TransformBundle`] with no translation, rotation, and a scale of 1 on all axes.
|
|
pub const IDENTITY: Self = TransformBundle {
|
|
local: Transform::IDENTITY,
|
|
global: GlobalTransform::IDENTITY,
|
|
};
|
|
|
|
/// Creates a new [`TransformBundle`] from a [`Transform`].
|
|
///
|
|
/// This initializes [`GlobalTransform`] as identity, to be updated later by the
|
|
/// [`bevy_app::PostUpdate`] schedule.
|
|
#[inline]
|
|
pub const fn from_transform(transform: Transform) -> Self {
|
|
TransformBundle {
|
|
local: transform,
|
|
..Self::IDENTITY
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<Transform> for TransformBundle {
|
|
#[inline]
|
|
fn from(transform: Transform) -> Self {
|
|
Self::from_transform(transform)
|
|
}
|
|
}
|