Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Migration to bevy_ecs_tiled v0.15

This guide outlines the steps required to migrate your project to version 0.15 of bevy_ecs_tiled.

This version still targets Bevy v0.20: there is no Bevy upgrade involved, only bevy_ecs_tiled API changes.

Main Changes

  • API cleanup: the get_ prefix is dropped from TiledEvent accessors, TiledMapStorage / TiledWorldStorage lookups and map helper functions, following Rust API guidelines
  • Storage iterators now return opaque iterators yielding owned values
  • Typed loader errors: unsupported orientations and Tiled parsing errors are reported as dedicated error variants instead of panicking or being converted to std::io::Error
  • No more panics when exporting Tiled types or reading invalid user properties
  • Isometric and hexagonal maps had multiple fixes and should now be positioned like in Tiled
  • New debug plugin TiledDebugMapAabbPlugin to display maps bounding boxes

Migration Steps

1. Update Dependencies

bevy = "0.20"
bevy_ecs_tiled = "0.15"

2. Drop the get_ Prefix from Accessors

All getters lose their get_ prefix, their signatures being otherwise unchanged. In most cases, removing get_ from the method name is all you need to do.

TiledEvent accessors

Before (v0.14)After (v0.15)
get_world_entity()world_entity()
get_world_asset()world_asset()
get_world()world()
get_map_entity()map_entity()
get_map_asset()map_asset()
get_map()map()
get_layer_entity()layer_entity()
get_layer_id()layer_id()
get_layer()layer()
get_tilemap_entity()tilemap_entity()
get_tilemap_tileset_id()tilemap_tileset_id()
get_tilemap_tileset()tilemap_tileset()
get_tile_entity()tile_entity()
get_tile_pos()tile_pos()
get_tile_id()tile_id()
get_tile()tile()
get_object_entity()object_entity()
get_object_id()object_id()
get_object()object()

TiledEvent<ColliderCreated>::get_tiles() is also renamed to TiledEvent<ColliderCreated>::tiles().

TiledMapStorage and TiledWorldStorage lookups

Before (v0.14)After (v0.15)
TiledMapStorage::get_layer_entity()TiledMapStorage::layer_entity()
TiledMapStorage::get_layer_id()TiledMapStorage::layer_id()
TiledMapStorage::get_layer()TiledMapStorage::layer()
TiledMapStorage::get_tile_entities()TiledMapStorage::tile_entities()
TiledMapStorage::get_tile_id()TiledMapStorage::tile_id()
TiledMapStorage::get_tile()TiledMapStorage::tile()
TiledMapStorage::get_object_entity()TiledMapStorage::object_entity()
TiledMapStorage::get_object_id()TiledMapStorage::object_id()
TiledMapStorage::get_object()TiledMapStorage::object()
TiledWorldStorage::get_map_entity()TiledWorldStorage::map_entity()
TiledWorldStorage::get_map_id()TiledWorldStorage::map_id()

Helper functions

Before (v0.14)After (v0.15)
get_layer_from_map()layer_from_map()
get_tileset_from_map()tileset_from_map()
get_tile_from_map()tile_from_map()
get_object_from_map()object_from_map()

Before (v0.14):

#![allow(unused)]
fn main() {
fn on_object_created(
    object_created: On<TiledEvent<ObjectCreated>>,
    assets: Res<Assets<TiledMapAsset>>,
) {
    let Some(object) = object_created.event().get_object(&assets) else {
        return;
    };
    // ...
}
}

After (v0.15):

#![allow(unused)]
fn main() {
fn on_object_created(
    object_created: On<TiledEvent<ObjectCreated>>,
    assets: Res<Assets<TiledMapAsset>>,
) {
    let Some(object) = object_created.event().object(&assets) else {
        return;
    };
    // ...
}
}

3. Update TiledMapStorage and TiledWorldStorage Usage

Iterators

layers(), objects(), tiles() and maps() no longer expose the inner HashMap iterator: they return an impl Iterator yielding owned IDs and entities (and a &[Entity] slice for tiles).

Before (v0.14):

#![allow(unused)]
fn main() {
for (id, entity) in storage.objects() {
    // `id: &u32`, `entity: &Entity`
    let entity = *entity;
}
}

After (v0.15):

#![allow(unused)]
fn main() {
for (id, entity) in storage.objects() {
    // `id: u32`, `entity: Entity`
}
}

Remove any now unneeded dereference (*id, *entity) or .copied() / .cloned() call. If you relied on HashMap iterator specific methods (eg. len()), use the generic Iterator API instead (eg. count()).

Tile entities

TiledMapStorage::tile_entities() (formerly get_tile_entities()) now returns a &[Entity] instead of a cloned Vec<Entity>. Call .to_vec() if you really need an owned value.

clear() is no longer public

TiledMapStorage::clear() and TiledWorldStorage::clear() have been removed from the public API. To respawn a map or a world, insert the RespawnTiledMap or RespawnTiledWorld component instead:

#![allow(unused)]
fn main() {
commands.entity(map_entity).insert(RespawnTiledMap);
}

4. Handle New Loader Errors

TiledMapLoaderError and TiledWorldLoaderError changed:

  • Tiled parsing errors are now reported as a new Tiled variant, holding the original tiled::Error, instead of being converted to std::io::Error (ie. the Io variant).
  • Maps with an unsupported orientation (staggered or oblique) now fail to load with TiledMapLoaderError::UnsupportedOrientation instead of panicking during spawn.
  • Both enums are now #[non_exhaustive]: if you match on them, add a wildcard arm.
#![allow(unused)]
fn main() {
match error {
    TiledMapLoaderError::Io(e) => error!("I/O error: {e}"),
    TiledMapLoaderError::Tiled(e) => error!("Invalid Tiled map: {e}"),
    TiledMapLoaderError::UnsupportedOrientation(o) => error!("Unsupported orientation: {o:?}"),
    _ => error!("Failed to load map: {error}"),
}
}

A non-panicking try_tilemap_type_from_map() helper is also available, returning None for unsupported orientations.

6. Handle export_types() Result

If you call export_types() directly, it now returns a std::io::Result<()> instead of panicking:

#![allow(unused)]
fn main() {
if let Err(e) = export_types(&registry, "tiled_types.json", &TiledFilter::All) {
    error!("Failed to export Tiled types: {e}");
}
}

When types export is configured through the plugin (TiledPluginConfig::tiled_types_export_file), a failure now logs an error instead of crashing the application.


Resources