Bevy 0.15.x API Deprecations Guide

This guide documents the deprecated APIs in Bevy 0.15.x and their recommended replacements for use in the Rummage project.

Bundle Deprecations

Bevy 0.15.x has deprecated many bundle types in favor of a more streamlined component approach.

Rendering Bundles

DeprecatedReplacement
Text2dBundleText2d component
SpriteBundleSprite component
ImageBundleImage component

Example:

#![allow(unused)]
fn main() {
// ❌ Deprecated approach
commands.spawn(SpriteBundle {
    texture: asset_server.load("path/to/sprite.png"),
    transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)),
    ..default()
});

// ✅ New approach
commands.spawn((
    Sprite::default(),
    asset_server.load::<Image>("path/to/sprite.png"),
    Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)),
));
}

UI Bundles

DeprecatedReplacement
NodeBundleNode component
ButtonBundleCombine Button with other components
TextBundleCombine Text and other components

Example:

#![allow(unused)]
fn main() {
// ❌ Deprecated approach
commands.spawn(NodeBundle {
    style: Style {
        width: Val::Px(200.0),
        height: Val::Px(100.0),
        ..default()
    },
    background_color: Color::WHITE.into(),
    ..default()
});

// ✅ New approach
commands.spawn((
    Node {
        // Node properties
    },
    Style {
        width: Val::Px(200.0),
        height: Val::Px(100.0),
        ..default()
    },
    BackgroundColor(Color::WHITE),
));
}

Camera Bundles

DeprecatedReplacement
Camera2dBundleCamera2d component
Camera3dBundleCamera3d component

Example:

#![allow(unused)]
fn main() {
// ❌ Deprecated approach
commands.spawn(Camera2dBundle::default());

// ✅ New approach
commands.spawn(Camera2d::default());
}

Transform Bundles

DeprecatedReplacement
SpatialBundleCombine Transform and Visibility
TransformBundleTransform component
GlobalTransform (manual insertion)Just insert Transform

Example:

#![allow(unused)]
fn main() {
// ❌ Deprecated approach
commands.spawn(SpatialBundle::default());

// ✅ New approach
commands.spawn((
    Transform::default(),
    Visibility::default(),
));
}

Required Component Pattern

Bevy 0.15.x uses a "required component" pattern where inserting certain components will automatically insert their prerequisites. This means you no longer need to explicitly add all dependencies.

Examples of Required Component Pattern

#![allow(unused)]
fn main() {
// Camera2d will automatically add Camera, Transform, and other required components
commands.spawn(Camera2d::default());

// Transform will automatically add GlobalTransform
commands.spawn(Transform::default());

// Sprite will automatically add TextureAtlas related components
commands.spawn(Sprite::default());
}

Event API Changes

DeprecatedReplacement
Events::get_reader()Events::get_cursor()
ManualEventReaderEventCursor

Example:

#![allow(unused)]
fn main() {
// ❌ Deprecated approach
let mut reader = events.get_reader();
for event in reader.read(&events) {
    // Handle event
}

// ✅ New approach
let mut cursor = events.get_cursor();
for event in cursor.read(&events) {
    // Handle event
}
}

Entity Access Changes

DeprecatedReplacement
Commands.get_or_spawn()Commands.entity() or Commands.spawn()
World.get_or_spawn()World.entity() or World.spawn()

Example:

#![allow(unused)]
fn main() {
// ❌ Deprecated approach
commands.get_or_spawn(entity).insert(MyComponent);

// ✅ New approach
if world.contains_entity(entity) {
    commands.entity(entity).insert(MyComponent);
} else {
    commands.spawn((entity, MyComponent));
}
}

UI Node Access Changes

DeprecatedReplacement
Node::logical_rect()Rect::from_center_size with translation and node size
Node::physical_rect()Rect::from_center_size with translation and node size

Example:

#![allow(unused)]
fn main() {
// ❌ Deprecated approach
let rect = node.logical_rect(transform);

// ✅ New approach
let rect = Rect::from_center_size(
    transform.translation().truncate(),
    node.size(),
);
}

Window and Input Changes

DeprecatedReplacement
CursorIcon field in WindowCursorIcon component on window entity
Window.add_*_listener methodsUse event systems

Example:

#![allow(unused)]
fn main() {
// ❌ Deprecated approach
window.cursor_icon = CursorIcon::Hand;

// ✅ New approach
commands.entity(window_entity).insert(CursorIcon::Hand);
}

Best Practices

  1. Check Compiler Warnings: Always check for compiler warnings after making changes, as they will indicate usage of deprecated APIs.
  2. Use Component Approach: Prefer the component-based approach over bundles.
  3. Required Components: Leverage Bevy's automatic insertion of required components.
  4. Run Tests: Run tests frequently to ensure compatibility.

Troubleshooting

If you encounter issues after replacing deprecated APIs:

  1. Check Component Dependencies: Some components may have implicit dependencies that need to be explicitly added.
  2. Verify Insertion Order: In some cases, the order of component insertion matters.
  3. Update Queries: Update your queries to match the new component structure.
  4. Check Bevy Changelog: Refer to the Bevy changelog for detailed API changes.