feat!: Got rid of UpdateShapes component

- update_collider_shapes now filters by Changed<Transform>
This commit is contained in:
Alexey 2026-02-15 18:05:27 +03:00
commit 9d0ae295ee
2 changed files with 6 additions and 26 deletions

View file

@ -130,29 +130,12 @@ impl Collider {
} }
} }
#[derive(Component, Debug)]
/// Add this component on entities, which have their [`Transform`] updated.
/// Used for [`update_collider_shapes`] system
pub struct UpdateShapes;
/// Update collider shapes to match new [`Transform`] /// Update collider shapes to match new [`Transform`]
pub fn update_collider_shapes( pub fn update_collider_shapes(
mut commands: Commands, colliders: Query<(&mut Collider, &Transform), Changed<Transform>>,
colliders: Query<(&mut Collider, &Transform, Entity), Added<UpdateShapes>>,
) { ) {
for (mut collider, transform, entity) in colliders { for (mut collider, transform) in colliders {
collider.update_shapes_position(&transform.translation.xy()); collider.update_shapes_position(&transform.translation.xy());
commands.entity(entity).remove::<UpdateShapes>();
}
}
/// Detect new colliders and automatically insert [`UpdateShapes`]
pub fn detect_colliders(
mut commands: Commands,
query: Query<Entity, Added<Collider>>,
) {
for entity in query {
commands.entity(entity).insert(UpdateShapes);
} }
} }
@ -189,6 +172,6 @@ pub struct CollisionPlugin;
impl Plugin for CollisionPlugin { impl Plugin for CollisionPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_systems(PostUpdate, (detect_colliders, update_collider_shapes, check_for_collisions).chain()); app.add_systems(PostUpdate, (update_collider_shapes, check_for_collisions).chain());
} }
} }

View file

@ -1,5 +1,5 @@
use bevy::prelude::*; use bevy::prelude::*;
use bevy_collision_plugin::{Collider, CollisionEvent, CollisionPlugin, CollisionShape, UpdateShapes}; use bevy_collision_plugin::{Collider, CollisionEvent, CollisionPlugin, CollisionShape};
const CHECKED_GROUPS: usize = 1 << 0 | 1 << 1; const CHECKED_GROUPS: usize = 1 << 0 | 1 << 1;
@ -48,13 +48,10 @@ fn firstgroup_collider_bundle() -> impl Bundle {
} }
fn move_collider( fn move_collider(
mut commands: Commands, query: Query<&mut Transform, With<MovingCollider>>,
query: Query<(Entity, &mut Transform), With<MovingCollider>>,
) { ) {
for (entity, mut transform) in query { for mut transform in query {
transform.translation.x += 50.; transform.translation.x += 50.;
commands.entity(entity)
.insert(UpdateShapes);
} }
} }