Trouv / bevy_ecs_ldtk

ECS-friendly ldtk plugin for bevy, leveraging bevy_ecs_tilemap
Other
630 stars 74 forks source link

Tilemap rendering breaks when spawning a level a second time in bevy_ecs_ldtk 0.8 #233

Closed oberzs closed 7 months ago

oberzs commented 9 months ago

Hello, loving the plugin btw

Environment:

On the first couple selections it works perfectly and loads all the neighboring levels and renders all the tiles. After a couple more selections the tile rendering just stops updating, it renders the tiles from a previous selection.

In the bevy_editor_pls hierarchy I can see that this plugin is still loading the levels correctly, with all the tile entities in there, but the render on my screen has been frozen to just show an earlier selection.

These are my LdtkSettings:

.insert_resource(LdtkSettings {
    level_spawn_behavior: LevelSpawnBehavior::UseWorldTranslation {
        load_level_neighbors: true,
    },
    level_background: LevelBackground::Nonexistent,
    ..default()
})

This is my code for loading the world bundle:

fn test_spawn_world(mut commands: Commands, assets: Res<AssetServer>) {
    commands.spawn(LdtkWorldBundle {
        ldtk_handle: assets.load("worlds/world.ldtk"),
        ..default()
    });
}

This is my code for selecting and loading levels:

fn test_select_level(mut commands: Commands, keys: Res<Input<KeyCode>>) {
    if keys.just_pressed(KeyCode::Key0) {
        commands.insert_resource(LevelSelection::Identifier("level_0".into()));
    }
    if keys.just_pressed(KeyCode::Key1) {
        commands.insert_resource(LevelSelection::Identifier("level_1".into()));
    }
    if keys.just_pressed(KeyCode::Key2) {
        commands.insert_resource(LevelSelection::Identifier("level_2".into()));
    }
    if keys.just_pressed(KeyCode::Key3) {
        commands.insert_resource(LevelSelection::Identifier("level_3".into()));
    }
}
Trouv commented 9 months ago

Hello, thanks for the issue!

Have you tried using this patch? https://github.com/Trouv/bevy_ecs_ldtk/issues/174#issuecomment-1676160498

oberzs commented 9 months ago

Yes, that works perfectly, thank you!

Trouv commented 9 months ago

I'm renaming/reopening this issue, and pinning it since many users have been running into this. Will close once the bevy_ecs_tilemap fix has been released.

Trouv commented 9 months ago

I believe this is the MR that fixed it in bevy_ecs_tilemap btw: https://github.com/StarArawn/bevy_ecs_tilemap/pull/451 (commit b87874e9f0598176aaedf4d875927eb668312c30)

janos-r commented 7 months ago

After upgrading my POC project rusty-woods I experienced possibly the same issue as described in ecs_tilemap - first level load looks fine, but after going to level2 (into the house) or back out to the first level, the tiles are gone on both levels. I will try this again in a future version.

Unfortunately adding this to my Cargo.toml didn't help. Making me question if the tilemap fix helped.

[patch.crates-io]
bevy_ecs_tilemap = { git = "http://github.com/StarArawn/bevy_ecs_tilemap", version = "0.11", branch = "main" }

Eitherway, I am apparently not the only one finding something similar. I hope that future versions will have this fixed. I am happy that your project keeps growing. I was trying to upgrade my old POC out of curiosity. I hope I can find the cause of the bug in the future so I can keep a nice looking POC ^^

Trouv commented 7 months ago

Strange - I was experiencing this before too and using the newer bevy_ecs_tilemap did fix it for me. BTW I believe the "fix commit" I referenced above has been released in a bevy_ecs_tilemap release now. Could you tried using bevy_ecs_tilemap = "0.11.1" and cargo update?

janos-r commented 7 months ago

Strange - I was experiencing this before too and using the newer bevy_ecs_tilemap did fix it for me. BTW I believe the "fix commit" I referenced above has been released in a bevy_ecs_tilemap release now. Could you tried using bevy_ecs_tilemap = "0.11.1" and cargo update?

No way! That fixed it! Having a pure bevy_ecs_tilemap = { version = "0.11.1", features = ["atlas"] } fixed it for me!

Thank you ^^ And good luck going forward!

janos-r commented 7 months ago

A little surprised that 0.11.1 didn't get pulled down automatically when I had it specified as 0.11 - I always thought that's how it works based on https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-dependencies-from-cratesio Anyway, thanks once more for the tip ^^

Trouv commented 7 months ago

Yeah, idk, I would say that it wouldn't update automatically if you previously downloaded 0.11.0 w/o a cargo update, but it sounds like you upgraded straight to 0.11 so it should have downloaded 0.11.1.

Trouv commented 7 months ago

Anyway - since the fix has now been released in bevy_ecs_tilemap version 0.11.1, I'm going to close this issue.