Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance issues with static colliders and bevy_ecs_tilemap #615

Closed
vladinator1000 opened this issue Jan 4, 2025 · 4 comments
Closed
Labels
A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality C-Performance Improvements or questions related to performance

Comments

@vladinator1000
Copy link

vladinator1000 commented Jan 4, 2025

Hi there, I added a static collider to every tile in this example from bevy_ecs_tilemap. My FPS slowed down to a crawl. Is this a known limitation to Avian when dealing with high numbers of static colliders, do I have to generate my own mesh in that case?

I have a few hundred tiles active at a time and they are constantly getting spawned/de-spawned procedurally. Here's what my scene looks like without any colliders:

2025-01-03.12-18-00.mp4
@StrikeForceZero
Copy link

im not using bevy_ecs_tilemap but im generating a grid map where all the statics are touching and ran into the same problem. if you use https://docs.rs/avian2d/latest/avian2d/collision/struct.CollisionLayers.html and just make it so the tile doesn't filter the same layer its a member of then it should improve performance. at least it did for me

@vladinator1000
Copy link
Author

Thank you @StrikeForceZero, using collision layers fixed the performance problem ❤️

#[derive(PhysicsLayer, Default)]
pub enum CollisionLayer {
  #[default]
  Default,
  Player,
  Item,
  Ground,
}

// later when spawning tiles I added the layers like this:
 let tile_entity = commands
        .spawn((
          RigidBody::Static,
          Collider::rectangle(TILE_SIZE.x, TILE_SIZE.y),
          CollisionLayers::new(
            crate::physics::CollisionLayer::Ground,
            [
              crate::physics::CollisionLayer::Default,
              crate::physics::CollisionLayer::Player,
              crate::physics::CollisionLayer::Item,
            ],
          ),
          Transform::from_translation(world_pos.extend(0.0)),
          TileBundle {
            position: tile_pos,
            texture_index,
            tilemap_id: TilemapId(tilemap_entity),
            ..Default::default()
          },
        ))
        .id();

@Jondolf
Copy link
Owner

Jondolf commented Jan 11, 2025

@vladinator1000 Have you verified with the PhysicsDebugPlugin that the tiles are actually at the correct positions? In the chunking example you linked, with a static rigid body and collider for each tile, I'm getting ~300 fps in debug mode and 1500-1700 fps in release mode, not using CollisionLayers or anything like that.

debug

release

Also see StarArawn/bevy_ecs_tilemap#504 for a somewhat related issue.

@Jondolf Jondolf added C-Performance Improvements or questions related to performance A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality labels Jan 11, 2025
@vladinator1000
Copy link
Author

@Jondolf it does look like my tiles are touching 👀
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality C-Performance Improvements or questions related to performance
Projects
None yet
Development

No branches or pull requests

3 participants