MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / DestroyChildren

Method DestroyChildren

Source/Engine/Level/Actor.cpp:506–577  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

504}
505
506void Actor::DestroyChildren(float timeLeft)
507{
508 if (Children.IsEmpty())
509 return;
510 PROFILE_CPU();
511
512 // Actors system doesn't support editing scene hierarchy from multiple threads
513 if (!IsInMainThread() && IsDuringPlay())
514 {
515 LOG(Error, "Editing scene hierarchy is only allowed on a main thread.");
516 return;
517 }
518
519 // Get all actors
520 Array<Actor*> children = Children;
521
522#if USE_EDITOR
523 // Inform Editor beforehand
524 Level::callActorEvent(Level::ActorEventType::OnActorDestroyChildren, this, nullptr);
525#endif
526
527 if (_scene && IsActiveInHierarchy())
528 {
529 // Disable children
530 for (Actor* child : children)
531 {
532 if (child->IsActiveInHierarchy())
533 {
534 child->OnDisableInHierarchy();
535 }
536 }
537 }
538
539 Level::ScenesLock.Lock();
540
541 // Remove children all at once
542 Children.Clear();
543 _isHierarchyDirty = true;
544
545 // Unlink children from scene hierarchy
546 for (Actor* child : children)
547 {
548 child->_parent = nullptr;
549 if (!_isActiveInHierarchy)
550 child->_isActive = false; // Force keep children deactivated to reduce overhead during destruction
551 if (_scene)
552 child->SetSceneInHierarchy(nullptr);
553 }
554
555 Level::ScenesLock.Unlock();
556
557 // Inform actors about this
558 for (Actor* child : children)
559 {
560 child->OnParentChanged();
561 }
562
563 // Unlink children for hierarchy

Callers

nothing calls this directly

Calls 10

IsInMainThreadFunction · 0.85
IsActiveInHierarchyFunction · 0.85
OnDisableInHierarchyMethod · 0.80
LockMethod · 0.80
SetSceneInHierarchyMethod · 0.80
UnlockMethod · 0.80
DeleteObjectMethod · 0.80
IsEmptyMethod · 0.45
ClearMethod · 0.45
OnParentChangedMethod · 0.45

Tested by

no test coverage detected