@@ -1035,7 +1035,7 @@ impl<'w> BundleInserter<'w> {
1035
1035
change_tick : Tick ,
1036
1036
) -> Self {
1037
1037
// SAFETY: We will not make any accesses to the command queue, component or resource data of this world
1038
- let mut bundle_info = world. bundles . get_unchecked ( bundle_id) ;
1038
+ let bundle_info = world. bundles . get_unchecked ( bundle_id) ;
1039
1039
let bundle_id = bundle_info. id ( ) ;
1040
1040
let ( new_archetype_id, is_new_created) = bundle_info. insert_bundle_into_archetype (
1041
1041
& mut world. archetypes ,
@@ -1045,12 +1045,7 @@ impl<'w> BundleInserter<'w> {
1045
1045
archetype_id,
1046
1046
) ;
1047
1047
1048
- if is_new_created {
1049
- world. trigger ( ArchetypeCreated ( new_archetype_id) ) ;
1050
- bundle_info = world. bundles . get_unchecked ( bundle_id) ;
1051
- }
1052
-
1053
- if new_archetype_id == archetype_id {
1048
+ let inserter = if new_archetype_id == archetype_id {
1054
1049
let archetype = & mut world. archetypes [ archetype_id] ;
1055
1050
// SAFETY: The edge is assured to be initialized when we called insert_bundle_into_archetype
1056
1051
let archetype_after_insert = unsafe {
@@ -1110,7 +1105,15 @@ impl<'w> BundleInserter<'w> {
1110
1105
world : world. as_unsafe_world_cell ( ) ,
1111
1106
}
1112
1107
}
1108
+ } ;
1109
+
1110
+ if is_new_created {
1111
+ inserter
1112
+ . world
1113
+ . into_deferred ( )
1114
+ . trigger ( ArchetypeCreated ( new_archetype_id) ) ;
1113
1115
}
1116
+ inserter
1114
1117
}
1115
1118
1116
1119
/// # Safety
@@ -1426,7 +1429,7 @@ impl<'w> BundleRemover<'w> {
1426
1429
bundle_id : BundleId ,
1427
1430
require_all : bool ,
1428
1431
) -> Option < Self > {
1429
- let mut bundle_info = world. bundles . get_unchecked ( bundle_id) ;
1432
+ let bundle_info = world. bundles . get_unchecked ( bundle_id) ;
1430
1433
// SAFETY: Caller ensures archetype and bundle ids are correct.
1431
1434
let ( new_archetype_id, is_new_created) = unsafe {
1432
1435
bundle_info. remove_bundle_from_archetype (
@@ -1444,11 +1447,6 @@ impl<'w> BundleRemover<'w> {
1444
1447
return None ;
1445
1448
}
1446
1449
1447
- if is_new_created {
1448
- world. trigger ( ArchetypeCreated ( new_archetype_id) ) ;
1449
- bundle_info = world. bundles . get_unchecked ( bundle_id) ;
1450
- }
1451
-
1452
1450
let ( old_archetype, new_archetype) =
1453
1451
world. archetypes . get_2_mut ( archetype_id, new_archetype_id) ;
1454
1452
@@ -1462,13 +1460,20 @@ impl<'w> BundleRemover<'w> {
1462
1460
Some ( ( old. into ( ) , new. into ( ) ) )
1463
1461
} ;
1464
1462
1465
- Some ( Self {
1463
+ let remover = Self {
1466
1464
bundle_info : bundle_info. into ( ) ,
1467
1465
new_archetype : new_archetype. into ( ) ,
1468
1466
old_archetype : old_archetype. into ( ) ,
1469
1467
old_and_new_table : tables,
1470
1468
world : world. as_unsafe_world_cell ( ) ,
1471
- } )
1469
+ } ;
1470
+ if is_new_created {
1471
+ remover
1472
+ . world
1473
+ . into_deferred ( )
1474
+ . trigger ( ArchetypeCreated ( new_archetype_id) ) ;
1475
+ }
1476
+ Some ( remover)
1472
1477
}
1473
1478
1474
1479
/// This can be passed to [`remove`](Self::remove) as the `pre_remove` function if you don't want to do anything before removing.
@@ -1689,7 +1694,7 @@ impl<'w> BundleSpawner<'w> {
1689
1694
bundle_id : BundleId ,
1690
1695
change_tick : Tick ,
1691
1696
) -> Self {
1692
- let mut bundle_info = world. bundles . get_unchecked ( bundle_id) ;
1697
+ let bundle_info = world. bundles . get_unchecked ( bundle_id) ;
1693
1698
let ( new_archetype_id, is_new_created) = bundle_info. insert_bundle_into_archetype (
1694
1699
& mut world. archetypes ,
1695
1700
& mut world. storages ,
@@ -1698,20 +1703,22 @@ impl<'w> BundleSpawner<'w> {
1698
1703
ArchetypeId :: EMPTY ,
1699
1704
) ;
1700
1705
1701
- if is_new_created {
1702
- world. trigger ( ArchetypeCreated ( new_archetype_id) ) ;
1703
- bundle_info = world. bundles . get_unchecked ( bundle_id) ;
1704
- }
1705
-
1706
1706
let archetype = & mut world. archetypes [ new_archetype_id] ;
1707
1707
let table = & mut world. storages . tables [ archetype. table_id ( ) ] ;
1708
- Self {
1708
+ let spawner = Self {
1709
1709
bundle_info : bundle_info. into ( ) ,
1710
1710
table : table. into ( ) ,
1711
1711
archetype : archetype. into ( ) ,
1712
1712
change_tick,
1713
1713
world : world. as_unsafe_world_cell ( ) ,
1714
+ } ;
1715
+ if is_new_created {
1716
+ spawner
1717
+ . world
1718
+ . into_deferred ( )
1719
+ . trigger ( ArchetypeCreated ( new_archetype_id) ) ;
1714
1720
}
1721
+ spawner
1715
1722
}
1716
1723
1717
1724
#[ inline]
0 commit comments