bevy_ecs_tilemap icon indicating copy to clipboard operation
bevy_ecs_tilemap copied to clipboard

Hot reloading tilesets

Open Trouv opened this issue 2 years ago • 9 comments

Using bevy_ecs_tilemap 0.5

I seem to remember when working with bevy_ecs_tilemap pre-0.5, updating a tileset asset with asset_server.watch_for_changes() on would automatically update the rendered tilemaps in game. This doesn't seem to be working anymore. Might be on my end? Also I might be misremembering. I imagine the chunking and custom rendering stuff going on could complicate hot reloading.

Trouv avatar Apr 14 '22 02:04 Trouv

I wasn't about to reproduce this. I did need to add the watch for changes setting to get it to work however though.

StarArawn avatar Apr 21 '22 11:04 StarArawn

Maybe it's a difference between our systems? I'm on linux.

I'm also now testing this on bevy_ecs_tilemap main, not 0.5.

I've been able to reproduce this with the map example. My minor edits are on my fork's branch issue_172 https://github.com/Trouv/bevy_ecs_tilemap/tree/issue_172

I didn't change much:

  • turned on watch for changes
  • made it so the set_texture_filters_to_nearest system works on AssetEvent::Modified as well

I've tried setting watch_for_changes via AssetServer::watch_for_changes() and AssetServerSettings::watch_for_changes, both separately and together.

Then, while the example is running I just hit it with $ cp assets/tiles2.png assets/tiles.png. No hot reloading.

Bevy's filesystem_watcher feature should be enabled since the dev-dependencies don't turn off default-features.

Trouv avatar Apr 21 '22 23:04 Trouv

Accidentally closed this, sorry

Trouv avatar Apr 21 '22 23:04 Trouv

Maybe it's a difference between our systems? I'm on linux.

I'm also now testing this on bevy_ecs_tilemap main, not 0.5.

I've been able to reproduce this with the map example. My minor edits are on my fork's branch issue_172 https://github.com/Trouv/bevy_ecs_tilemap/tree/issue_172

I didn't change much:

  • turned on watch for changes
  • made it so the set_texture_filters_to_nearest system works on AssetEvent::Modified as well

I've tried setting watch_for_changes via AssetServer::watch_for_changes() and AssetServerSettings::watch_for_changes, both separately and together.

Then, while the example is running I just hit it with $ cp assets/tiles2.png assets/tiles.png. No hot reloading.

Bevy's filesystem_watcher feature should be enabled since the dev-dependencies don't turn off default-features.

This seems to be an issue on linux, I can't reproduce any of this on windows. 🤔

StarArawn avatar Apr 22 '22 16:04 StarArawn

The story gets stranger..

I went ahead and tried it on my windows partition and it didn't work there either?? Maybe it's just me??

I could maybe maybe see it being a hardware issue. In which case I should mention that my gpu is an Nvidia GTX 1060. It's weird that hot reloading would work fine for me when it comes to sprites and sprite sheets though.

Trouv avatar Apr 23 '22 00:04 Trouv

Can confirm this. linux, amd gpu, mesa drivers.

Cannot hot reload tile assets (they simply disappear completely, when I change them at runtime), but reloading works fine for all other sprites.

nerdachse avatar Apr 24 '22 20:04 nerdachse

Same as nerdachse here. Sometimes when a texture is reloaded this warning comes up: WARN bevy_asset::asset_server: encountered an error while loading an asset: Error reading image file textures/my_texture.png: failed to load an image: Format error decoding Png: unexpected EOF, this is an error in `bevy_render`. Maybe this helps. This doesn't happen when I move/copy a file like Trouv explained, but only when I hit save in GIMP. But however I initiate a reload, tile assets disappear while other sprites reload as expected.

ZarimSF avatar May 10 '22 20:05 ZarimSF

Same as nerdachse here. Sometimes when a texture is reloaded this warning comes up: WARN bevy_asset::asset_server: encountered an error while loading an asset: Error reading image file textures/my_texture.png: failed to load an image: Format error decoding Png: unexpected EOF, this is an error in `bevy_render`. Maybe this helps. This doesn't happen when I move/copy a file like Trouv explained, but only when I hit save in GIMP. But however I initiate a reload, tile assets disappear while other sprites reload as expected.

This sounds like a bug with bevy.

StarArawn avatar May 11 '22 14:05 StarArawn

For what it's worth, hot reloading works totally fine for me with Bevy 0.7, LDtk 1.0, and bevy_ecs_ldtk on Linux Pop_OS! ( Ubuntu ) 20.04. :man_shrugging:

zicklag avatar Jun 21 '22 19:06 zicklag

Just to add to this: Hot-reloading is not working for me also. It is working for "normal" sprites though.

Manjaro up-to-date, bevy 0.8.1, bevy_ecs_tilemap taken from main-branch. Any ideas where I could/should look for a solution/fix?

Affinator avatar Sep 19 '22 08:09 Affinator

I don't have time to really delve into it right now, but as a quick tip, if you use a path dependency in your Cargo.toml to depend on a locally cloned bevy_ecs_tilemap repo, you might try sticking println! here to see if the asset change is being detected at all.

That would give us some more direction on what might be causing it.

Note: Technically there's already a log call right there, so you might be able to run the game with RUST_LOG=info to see the message. I'm not sure, because it uses the log crate and the tracing macros that come with Bevy. I'm not sure if Bevy is setup to forward messages from the log crate.

zicklag avatar Sep 19 '22 16:09 zicklag

Checked it. Changes to the map (map.tmx) are reflected immediately and I can log that the AssetEvents are triggered.

Changes to the TileSet (tiles.png in this case) are not doing anything at all.

In my own project I tested that the AssetEvent<Handle< Image >> are actually send, but I assume the cached textures are not correctly updated.

Affinator avatar Sep 19 '22 19:09 Affinator

Ah OK. I'm not 100% sure if I ever tested updating the tilemap texture or not, so when I thought it was working for me I might have been wrong.

Without going deeper into the code I don't have any further suggestions on what to look at unfortunately, and I'm short for time at the moment so that's probably as far as I can try to help for now.

It sounds like we either need extra code in bevy_ecs_tilemap to handle refreshing the textures or something, or it's a driver/system. I don't think it's a Bevy issue, but still can't rule it out for sure without going deeper.

zicklag avatar Sep 19 '22 19:09 zicklag

As there was no commit to #273 since my last comment, hot reloading of tilesets is still broken for me.

Affinator avatar Sep 21 '22 17:09 Affinator

I just checked again to be sure: I checked out the main branch including the helpers overhaul.

I tested the tiled example:

  • changes to map.tmx are registered at runtime (changing the tile data and funnily changing the image source both work; i.e. switching between tiles.png and tiles2.png)
  • but changing the source image itself (tiles.png) does not do anything. A restart is needed to get the image to update.

Could someone please mark this issue as not resolved?

Affinator avatar Sep 22 '22 06:09 Affinator

I just tested again: This is still broken while using TextureAtlas or while using Vec<Handle<Image>> as a TilemapTexture.

Affinator avatar Oct 11 '22 08:10 Affinator

Yep, still broken for me as well. Tested with Bevy 0.9 and main branch (f01e8142).

--- a/examples/basic.rs
+++ b/examples/basic.rs
@@ -111,7 +111,7 @@ fn main() {
                 ..Default::default()
             },
             ..default()
-        }).set(ImagePlugin::default_nearest()))
+        }).set(ImagePlugin::default_nearest()).set(AssetPlugin { watch_for_changes: true, ..default() }))
         .add_plugin(TilemapPlugin)
         .add_startup_system(startup)
         .add_system(helpers::camera::movement)

Then I ran it and tried editing the tileset, but didn't see the changes before I quit and relaunched the the example.

johanhelsing avatar Nov 23 '22 21:11 johanhelsing

This problem is still happening to me on my Linux machine, too. bevy = "0.10"

772 avatar Apr 10 '23 19:04 772

Possible fix PR: #431.

andriyDev avatar May 23 '23 05:05 andriyDev

i have the same issue. hot reloading not working on mac os.

gerasim13 avatar Jun 21 '23 05:06 gerasim13