@@ -456,29 +456,23 @@ pub trait BuildWorldChildren {
456
456
457
457
impl < ' w > BuildWorldChildren for EntityMut < ' w > {
458
458
fn with_children ( & mut self , spawn_children : impl FnOnce ( & mut WorldChildBuilder ) ) -> & mut Self {
459
- {
460
- let entity = self . id ( ) ;
459
+ let entity = self . id ( ) ;
460
+ self . world_scope ( |world| {
461
461
let mut builder = WorldChildBuilder {
462
462
current_entity : None ,
463
463
parent_entities : vec ! [ entity] ,
464
- // SAFETY: The EntityLocation is updated before any other methods are called on self.
465
- world : unsafe { self . world_mut ( ) } ,
464
+ world,
466
465
} ;
467
-
468
466
spawn_children ( & mut builder) ;
469
- }
470
- self . update_location ( ) ;
467
+ } ) ;
471
468
self
472
469
}
473
470
474
471
fn push_children ( & mut self , children : & [ Entity ] ) -> & mut Self {
475
472
let parent = self . id ( ) ;
476
- {
477
- // SAFETY: The EntityLocation is updated before any other methods are called on self.
478
- let world = unsafe { self . world_mut ( ) } ;
473
+ self . world_scope ( |world| {
479
474
update_old_parents ( world, parent, children) ;
480
- self . update_location ( ) ;
481
- }
475
+ } ) ;
482
476
if let Some ( mut children_component) = self . get_mut :: < Children > ( ) {
483
477
children_component
484
478
. 0
@@ -492,13 +486,9 @@ impl<'w> BuildWorldChildren for EntityMut<'w> {
492
486
493
487
fn insert_children ( & mut self , index : usize , children : & [ Entity ] ) -> & mut Self {
494
488
let parent = self . id ( ) ;
495
- {
496
- // SAFETY: The EntityLocation is updated before any other methods are called on self.
497
- let world = unsafe { self . world_mut ( ) } ;
489
+ self . world_scope ( |world| {
498
490
update_old_parents ( world, parent, children) ;
499
- self . update_location ( ) ;
500
- }
501
-
491
+ } ) ;
502
492
if let Some ( mut children_component) = self . get_mut :: < Children > ( ) {
503
493
children_component
504
494
. 0
@@ -512,10 +502,9 @@ impl<'w> BuildWorldChildren for EntityMut<'w> {
512
502
513
503
fn remove_children ( & mut self , children : & [ Entity ] ) -> & mut Self {
514
504
let parent = self . id ( ) ;
515
- // SAFETY: The EntityLocation is updated before any other methods are called on self.
516
- let world = unsafe { self . world_mut ( ) } ;
517
- remove_children ( parent, children, world) ;
518
- self . update_location ( ) ;
505
+ self . world_scope ( |world| {
506
+ remove_children ( parent, children, world) ;
507
+ } ) ;
519
508
self
520
509
}
521
510
}
0 commit comments