From e554b7f531b5822aa04af94b9cbd1f0c67d3bb30 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 13 Apr 2022 21:34:13 +0200 Subject: [PATCH] Move `Actor.DestroyChildren` to C++ --- Source/Engine/Level/Actor.cpp | 11 +++++++++++ Source/Engine/Level/Actor.cs | 17 ----------------- Source/Engine/Level/Actor.h | 6 ++++++ 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Source/Engine/Level/Actor.cpp b/Source/Engine/Level/Actor.cpp index f58dfd587..5ca9e957a 100644 --- a/Source/Engine/Level/Actor.cpp +++ b/Source/Engine/Level/Actor.cpp @@ -418,6 +418,17 @@ Array Actor::GetChildren(const MClass* type) const return result; } +void Actor::DestroyChildren(float timeLeft) +{ + Array children = Children; + const bool useGameTime = timeLeft > ZeroTolerance; + for (Actor* child : children) + { + child->SetParent(nullptr, false, false); + child->DeleteObject(timeLeft, useGameTime); + } +} + bool Actor::HasTag(const StringView& tag) const { return HasTag() && tag == Level::Tags[_tag]; diff --git a/Source/Engine/Level/Actor.cs b/Source/Engine/Level/Actor.cs index 077ec346e..91f56798d 100644 --- a/Source/Engine/Level/Actor.cs +++ b/Source/Engine/Level/Actor.cs @@ -296,23 +296,6 @@ namespace FlaxEngine return output; } - /// - /// Destroys the children. Calls Object.Destroy on every child actor and unlink them for the parent. - /// - /// The time left to destroy object (in seconds). - [NoAnimate] - public void DestroyChildren(float timeLeft = 0.0f) - { - if (ChildrenCount == 0) - return; - Actor[] children = Children; - for (var i = 0; i < children.Length; i++) - { - children[i].Parent = null; - Destroy(children[i], timeLeft); - } - } - /// /// Gets the matrix that transforms a point from the world space to local space of the actor. /// diff --git a/Source/Engine/Level/Actor.h b/Source/Engine/Level/Actor.h index b31654c72..85dccfe13 100644 --- a/Source/Engine/Level/Actor.h +++ b/Source/Engine/Level/Actor.h @@ -242,6 +242,12 @@ public: return result; } + /// + /// Destroys the children. Calls Object.Destroy on every child actor and unlinks them for this actor. + /// + /// The time left to destroy object (in seconds). + API_FUNCTION(Attributes="NoAnimate") void DestroyChildren(float timeLeft = 0.0f); + public: ///