bevy_ecs_tilemap icon indicating copy to clipboard operation
bevy_ecs_tilemap copied to clipboard

AnimatedTile add/remove bug

Open bas-ie opened this issue 1 year ago • 2 comments
trafficstars

[dependencies]
bevy = { version = "0.12.1", features = ["wayland"] }
bevy_ecs_tilemap = { git = "https://github.com/StarArawn/bevy_ecs_tilemap", branch = "main" }

Hello! Enjoying using bevy_ecs_tilemap for a game jam, and thanks so much for your hard work.

I think I may have found a related bug to #474. I've been adding and removing AnimatedTile to support various action animations on a tile. (It's possible this isn't great practice, it's "jamcode" so we'll leave efficiency aside for now!) However, I notice that some of the time the animation doesn't stop when the component is removed.

I'd be happy to submit a PR but I'm a little new to the library, and not completely certain what's causing this inconsistent behaviour. I note that the workaround described in #473 solves the issue:

                      commands
                          .entity(character_entity)
                          .remove::<AnimatedTile>()
                          .insert(SeekingStorage { tile_pos: None });
                      if let Ok((_, mut color)) =
                          character_animation_q.get_mut(character_entity)
                      {
                          color.set_changed();
                      }

So presumably removing AnimatedTile just needs to trigger changed state? If you can point me in the right direction, I can have a crack at fixing it.

bas-ie avatar Jan 21 '24 22:01 bas-ie

Thanks for the report. Glad that workaround worked for you.

So presumably removing AnimatedTile just needs to trigger changed state? If you can point me in the right direction, I can have a crack at fixing it.

Sounds about right to me. I think this might be slightly more involved than the previous fix. It has been a while since I've looked at this code and I'm 100% sure this would work in an "extract system" but at a glance, I would try:

  • Splitting changed_tiles_query into
    • A query that just grabs the Entity with the same big "or changed" filter.
    • A separate query that actually retrieves data
  • Adding an Extract<RemovedComponents<AnimatedTile>> system param
  • Use iter_many to grab data tile data for entities that were either changed, or had that component removed.

rparrett avatar Jan 21 '24 23:01 rparrett

Thanks! I'll take a look after recovering from the jam :laughing:

bas-ie avatar Jan 22 '24 01:01 bas-ie