bevy/crates/bevy_render/src/spatial_bundle.rs
NiseVoid bdd0af6bfb
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());
```
2024-10-13 17:28:22 +00:00

72 lines
2.5 KiB
Rust

#![expect(deprecated)]
use bevy_ecs::prelude::Bundle;
use bevy_transform::prelude::{GlobalTransform, Transform};
use crate::view::{InheritedVisibility, ViewVisibility, Visibility};
/// A [`Bundle`] that allows the correct positional rendering of an entity.
///
/// It consists of transform components,
/// controlling position, rotation and scale of the entity,
/// but also visibility components,
/// which determine whether the entity is visible or not.
///
/// Parent-child hierarchies of entities must contain
/// all the [`Component`]s in this `Bundle`
/// to be rendered correctly.
///
/// [`Component`]: bevy_ecs::component::Component
#[derive(Bundle, Clone, Debug, Default)]
#[deprecated(
since = "0.15.0",
note = "Use the `Transform` and `Visibility` components instead.
Inserting `Transform` will now also insert a `GlobalTransform` automatically.
Inserting 'Visibility' will now also insert `InheritedVisibility` and `ViewVisibility` automatically."
)]
pub struct SpatialBundle {
/// The visibility of the entity.
pub visibility: Visibility,
/// The inherited visibility of the entity.
pub inherited_visibility: InheritedVisibility,
/// The view visibility of the entity.
pub view_visibility: ViewVisibility,
/// The transform of the entity.
pub transform: Transform,
/// The global transform of the entity.
pub global_transform: GlobalTransform,
}
impl SpatialBundle {
/// Creates a new [`SpatialBundle`] from a [`Transform`].
///
/// This initializes [`GlobalTransform`] as identity, and visibility as visible
#[inline]
pub const fn from_transform(transform: Transform) -> Self {
SpatialBundle {
transform,
..Self::INHERITED_IDENTITY
}
}
/// A [`SpatialBundle`] with inherited visibility and identity transform.
pub const INHERITED_IDENTITY: Self = SpatialBundle {
visibility: Visibility::Inherited,
inherited_visibility: InheritedVisibility::HIDDEN,
view_visibility: ViewVisibility::HIDDEN,
transform: Transform::IDENTITY,
global_transform: GlobalTransform::IDENTITY,
};
/// An invisible [`SpatialBundle`] with identity transform.
pub const HIDDEN_IDENTITY: Self = SpatialBundle {
visibility: Visibility::Hidden,
..Self::INHERITED_IDENTITY
};
}
impl From<Transform> for SpatialBundle {
#[inline]
fn from(transform: Transform) -> Self {
Self::from_transform(transform)
}
}