diff --git a/crates/bevy_ecs/src/component.rs b/crates/bevy_ecs/src/component.rs index ebb9896a606d3..7c018531c2bc3 100644 --- a/crates/bevy_ecs/src/component.rs +++ b/crates/bevy_ecs/src/component.rs @@ -55,14 +55,6 @@ mod sealed { impl Sealed for super::SparseStorage {} } -// ECS dependencies cannot derive Component, so we must implement it manually for relevant structs. -impl Component for bevy_tasks::Task -where - Self: Send + Sync + 'static, -{ - type Storage = TableStorage; -} - /// The storage used for a specific component type. /// /// # Examples diff --git a/examples/async_tasks/async_compute.rs b/examples/async_tasks/async_compute.rs index 065662cd32ff1..e5f7e30d8b0ab 100644 --- a/examples/async_tasks/async_compute.rs +++ b/examples/async_tasks/async_compute.rs @@ -43,6 +43,9 @@ fn add_assets( commands.insert_resource(BoxMaterialHandle(box_material_handle)); } +#[derive(Component)] +struct ComputeTransform(Task); + /// This system generates tasks simulating computationally intensive /// work that potentially spans multiple frames/ticks. A separate /// system, `handle_tasks`, will poll the spawned tasks on subsequent @@ -66,7 +69,7 @@ fn spawn_tasks(mut commands: Commands, thread_pool: Res) { }); // Spawn new entity and add our new task as a component - commands.spawn().insert(task); + commands.spawn().insert(ComputeTransform(task)); } } } @@ -78,12 +81,12 @@ fn spawn_tasks(mut commands: Commands, thread_pool: Res) { /// removes the task component from the entity. fn handle_tasks( mut commands: Commands, - mut transform_tasks: Query<(Entity, &mut Task)>, + mut transform_tasks: Query<(Entity, &mut ComputeTransform)>, box_mesh_handle: Res, box_material_handle: Res, ) { for (entity, mut task) in transform_tasks.iter_mut() { - if let Some(transform) = future::block_on(future::poll_once(&mut *task)) { + if let Some(transform) = future::block_on(future::poll_once(&mut task.0)) { // Add our new PbrBundle of components to our tagged entity commands.entity(entity).insert_bundle(PbrBundle { mesh: box_mesh_handle.clone(), @@ -93,7 +96,7 @@ fn handle_tasks( }); // Task is complete, so remove task component from entity - commands.entity(entity).remove::>(); + commands.entity(entity).remove::(); } } }