@@ -905,7 +905,9 @@ impl ScheduleGraph {
905
905
let mut dependency_flattened = self . get_dependency_flattened ( & set_systems) ;
906
906
907
907
// modify graph with auto sync points
908
- let dependency_flattened = self . insert_sync_points ( & mut dependency_flattened) ?;
908
+ if self . settings . auto_insert_sync_points {
909
+ dependency_flattened = self . insert_sync_points ( & mut dependency_flattened) ?;
910
+ }
909
911
910
912
// topsort
911
913
let mut dependency_flattened_dag = Dag {
@@ -1793,6 +1795,16 @@ pub struct ScheduleBuildSettings {
1793
1795
///
1794
1796
/// Defaults to [`LogLevel::Warn`].
1795
1797
pub hierarchy_detection : LogLevel ,
1798
+ /// Auto insert [`apply_deferred`] sync points after a system into the schedule,
1799
+ /// when there are [`Deferred`](crate::prelude::Deferred)
1800
+ /// in one system and there are ordering dependencies on that system. [`Commands`](crate::system::Commands) is one
1801
+ /// such deferred buffer.
1802
+ ///
1803
+ /// You may want to disable this if you only want to sync deferred params at the end of the schedule,
1804
+ /// or want to manually insert all your sync points.
1805
+ ///
1806
+ /// Defaults to `true`
1807
+ pub auto_insert_sync_points : bool ,
1796
1808
/// If set to true, node names will be shortened instead of the fully qualified type path.
1797
1809
///
1798
1810
/// Defaults to `true`.
@@ -1816,6 +1828,7 @@ impl ScheduleBuildSettings {
1816
1828
Self {
1817
1829
ambiguity_detection : LogLevel :: Ignore ,
1818
1830
hierarchy_detection : LogLevel :: Warn ,
1831
+ auto_insert_sync_points : true ,
1819
1832
use_shortnames : true ,
1820
1833
report_sets : true ,
1821
1834
}
@@ -1827,7 +1840,9 @@ mod tests {
1827
1840
use crate :: {
1828
1841
self as bevy_ecs,
1829
1842
prelude:: { Res , Resource } ,
1830
- schedule:: { IntoSystemConfigs , IntoSystemSetConfigs , Schedule , SystemSet } ,
1843
+ schedule:: {
1844
+ IntoSystemConfigs , IntoSystemSetConfigs , Schedule , ScheduleBuildSettings , SystemSet ,
1845
+ } ,
1831
1846
system:: Commands ,
1832
1847
world:: World ,
1833
1848
} ;
@@ -1927,4 +1942,25 @@ mod tests {
1927
1942
1928
1943
assert_eq ! ( schedule. executable. systems. len( ) , 2 ) ;
1929
1944
}
1945
+
1946
+ #[ test]
1947
+ fn disable_auto_sync_points ( ) {
1948
+ let mut schedule = Schedule :: default ( ) ;
1949
+ schedule. set_build_settings ( ScheduleBuildSettings {
1950
+ auto_insert_sync_points : false ,
1951
+ ..Default :: default ( )
1952
+ } ) ;
1953
+ let mut world = World :: default ( ) ;
1954
+ schedule. add_systems (
1955
+ (
1956
+ |mut commands : Commands | commands. insert_resource ( Resource1 ) ,
1957
+ |res : Option < Res < Resource1 > > | assert ! ( res. is_none( ) ) ,
1958
+ )
1959
+ . chain ( ) ,
1960
+ ) ;
1961
+ schedule. run ( & mut world) ;
1962
+
1963
+ // inserted a sync point
1964
+ assert_eq ! ( schedule. executable. systems. len( ) , 2 ) ;
1965
+ }
1930
1966
}
0 commit comments