diff --git a/src/pathfinding.rs b/src/pathfinding.rs index a64698a..c43f31a 100644 --- a/src/pathfinding.rs +++ b/src/pathfinding.rs @@ -16,6 +16,7 @@ use mapgen::Tile; use pathfinding::prelude::*; use crate::{ + commands::RunIfExistsExt, core::{Coordinates, PointLike}, map::{Map, MapObstruction}, navigation::{RotationSpeed, Speed}, @@ -238,12 +239,11 @@ fn calculate_path( shape_clone, ) }); - commands - .entity(entity) - .remove::() - .insert(Calculating(task)) - .remove::() - .remove::(); + commands.run_if_exists(entity, |mut entity| { + entity.insert(Calculating(task)); + entity.remove::(); + entity.remove::(); + }); } } }