diff --git a/crates/bevy_core/src/lib.rs b/crates/bevy_core/src/lib.rs index 8fc580848fce9..9c9a48b2dc09b 100644 --- a/crates/bevy_core/src/lib.rs +++ b/crates/bevy_core/src/lib.rs @@ -4,7 +4,9 @@ mod name; mod task_pool_options; +use bevy_ecs::schedule::IntoSystemDescriptor; use bevy_ecs::system::Resource; +use bevy_ecs::world::World; pub use bytemuck::{bytes_of, cast_slice, Pod, Zeroable}; pub use name::*; pub use task_pool_options::*; @@ -17,6 +19,7 @@ pub mod prelude { use bevy_app::prelude::*; use bevy_ecs::entity::Entity; +use bevy_tasks::prelude::tick_global_task_pools_on_main_thread; use bevy_utils::{Duration, HashSet, Instant}; use std::borrow::Cow; use std::ops::Range; @@ -34,6 +37,13 @@ impl Plugin for CorePlugin { .unwrap_or_default() .create_default_pools(); + // run function in an exclusive system to make sure it runs on main thread + fn tick_local_executors(_world: &mut World) { + tick_global_task_pools_on_main_thread(); + } + + app.add_system_to_stage(bevy_app::CoreStage::Last, tick.at_end()); + app.register_type::().register_type::(); register_rust_types(app); diff --git a/crates/bevy_tasks/src/lib.rs b/crates/bevy_tasks/src/lib.rs index 62c42a7717868..437bc3a9b8062 100644 --- a/crates/bevy_tasks/src/lib.rs +++ b/crates/bevy_tasks/src/lib.rs @@ -29,7 +29,10 @@ pub mod prelude { pub use crate::{ iter::ParallelIterator, slice::{ParallelSlice, ParallelSliceMut}, - usages::{AsyncComputeTaskPool, ComputeTaskPool, IoTaskPool}, + usages::{ + tick_global_task_pools_on_main_thread, AsyncComputeTaskPool, ComputeTaskPool, + IoTaskPool, + }, }; }