All bevy_ecs_tiled events are wrapped in a TiledEvent<E> structure. This wrapper provides essential context about the event's origin and includes helper methods to access related Tiled data. For instance, an event for a specific object will also provide access to the layer and map containing that object, allowing you to traverse the hierarchy easily.
use bevy::prelude::*;
use bevy_ecs_tiled::prelude::*;
fn handle_event(
mut object_events: MessageReader<TiledEvent<ObjectCreated>>,
) {
// Even though we receive an event for a Tiled object,
// we can retrieve information about the Tiled map
for e in object_events.read() {
let object_entity = e.origin;
if let Some(map_asset) = e.get_map_asset() {
info!("Received TiledEvent<ObjectCreated> for: '{:?}'", map_asset);
}
}
}