From df42f958e2c626e755b27219e2a92bfe5e71122b Mon Sep 17 00:00:00 2001 From: IceSentry Date: Thu, 17 Jul 2025 03:30:27 -0400 Subject: [PATCH] Remove task in handle_tasks in async_compute example --- examples/async_tasks/async_compute.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/async_tasks/async_compute.rs b/examples/async_tasks/async_compute.rs index 0b5a044563528..b315f8596b6ac 100644 --- a/examples/async_tasks/async_compute.rs +++ b/examples/async_tasks/async_compute.rs @@ -89,9 +89,7 @@ fn spawn_tasks(mut commands: Commands) { Mesh3d(box_mesh_handle), MeshMaterial3d(box_material_handle), transform, - )) - // Task is complete, so remove task component from entity - .remove::(); + )); }); command_queue @@ -108,11 +106,16 @@ fn spawn_tasks(mut commands: Commands) { /// tasks to see if they're complete. If the task is complete it takes the result, adds a /// new [`Mesh3d`] and [`MeshMaterial3d`] to the entity using the result from the task's work, and /// removes the task component from the entity. -fn handle_tasks(mut commands: Commands, mut transform_tasks: Query<&mut ComputeTransform>) { - for mut task in &mut transform_tasks { +fn handle_tasks( + mut commands: Commands, + mut transform_tasks: Query<(Entity, &mut ComputeTransform)>, +) { + for (entity, mut task) in &mut transform_tasks { if let Some(mut commands_queue) = block_on(future::poll_once(&mut task.0)) { // append the returned command queue to have it execute later commands.append(&mut commands_queue); + // Task is complete, so remove task component from entity + commands.entity(entity).remove::(); } } }