adrien-bon / bevy_ecs_tiled

Helpers for working with 2D tilemaps created with the Tiled map editor
MIT License
35 stars 8 forks source link

fix: Hot Reloading Issue #52

Closed shekohex closed 2 days ago

shekohex commented 3 days ago

Overview

While trying this awesome plugin and trying it out for the first time, I've noticed that whenever I change something in tiled, it does not hot-reload it in my game, even though I get this in my logs:

2024-11-24T20:42:16.878905Z  INFO bevy_ecs_tiled: Map 'maps/desert/desert.tmx' has finished loading, spawn it
2024-11-24T20:42:26.824795Z  INFO bevy_asset::server: Reloading maps\desert\desert.tmx because it has changed
...
2024-11-24T20:42:26.889222Z  INFO bevy_ecs_tiled: Map changed: AssetId<bevy_ecs_tiled::asset::TiledMap>{ index: 0, generation: 0}    

But nothing actually happens. Turns out that the query for the changed map, never return anything, or basically it does not match on anything.

After applying this fix, it now works and when I change something it tiled, it hot reloads it in my game.

...
2024-11-24T20:42:38.873064Z  INFO bevy_ecs_tiled: Map changed: AssetId<bevy_ecs_tiled::asset::TiledMap>{ index: 0, generation: 0}
2024-11-24T20:42:38.905235Z  INFO bevy_ecs_tiled: Map 'maps/desert/desert.tmx' has finished loading, spawn it

Changes

This pull request includes changes to the src/lib.rs file to update the handling of map events and improve code readability. The most important changes involve modifying the type used for map handles and updating the corresponding method calls.

Changes to map handle type:

Method call updates:

adrien-bon commented 2 days ago

Hi!

Thanks for the high qualtiy PR!

I did the same kind of changes on the Bevy 0.15 branch but I did not realize that not having these actually broke hot-reload. I will release a fixed version with you fix.

Again, thanks for your contribution 👍